:root {
    --navy-950: #0a1c30;
    --navy-900: #0b2b4a;
    --navy-800: #123a5e;
    --navy-700: #1a4a73;
    --navy-100: #e8eef5;

    --gold-500: #d97706;
    --gold-400: #f59e0b;
    --gold-100: #fef3e2;

    --slate-50:  #f7f9fb;
    --slate-100: #eef1f5;
    --slate-200: #e2e8f0;
    --slate-300: #cbd5e1;
    --slate-400: #94a3b8;
    --slate-500: #64748b;
    --slate-600: #475569;
    --slate-700: #334155;
    --slate-800: #1e293b;
    --slate-900: #0f172a;

    --green-100: #dcfce7; --green-700: #15803d;
    --amber-100: #fef3c7; --amber-700: #92400e;
    --red-100: #fee2e2;   --red-700: #b91c1c;
    --blue-100: #dbeafe;  --blue-700: #1d4ed8;
    --gray-100: #f1f5f9;  --gray-700: #475569;

    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 18px;

    --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06);
    --shadow-md: 0 4px 14px rgba(15, 23, 42, 0.08);
    --shadow-lg: 0 20px 50px rgba(15, 23, 42, 0.18);

    --sidebar-w: 258px;
    --topbar-h: 64px;

    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

* { box-sizing: border-box; }

html, body {
    margin: 0; padding: 0; height: 100%;
    font-family: var(--font-sans);
    background: var(--slate-50);
    color: var(--slate-800);
    font-size: 14.5px;
    -webkit-font-smoothing: antialiased;
}

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--slate-300); border-radius: 8px; }
::-webkit-scrollbar-thumb:hover { background: var(--slate-400); }

a { color: inherit; }
a.btn { text-decoration: none; }

.app-shell {
    display: grid;
    grid-template-columns: var(--sidebar-w) 1fr;
    grid-template-rows: 100vh;
}

.sidebar {
    background: linear-gradient(180deg, var(--navy-950) 0%, var(--navy-900) 100%);
    color: #cfe0f0;
    display: flex;
    flex-direction: column;
    padding: 22px 14px;
    position: relative;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 6px 10px 22px 10px;
    border-bottom: 1px solid rgba(255,255,255,0.08);
    margin-bottom: 18px;
}
.sidebar-brand img { height: 34px; width: auto; border-radius: 6px; }
.sidebar-brand .brand-fallback {
    width: 34px; height: 34px; border-radius: 8px; background: var(--gold-500);
    display: flex; align-items: center; justify-content: center; font-weight: 700; color: white; font-size: 15px;
}
.sidebar-brand .brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.sidebar-brand .brand-title { font-weight: 700; font-size: 0.95rem; color: #fff; letter-spacing: 0.2px; }
.sidebar-brand .brand-sub { font-size: 0.7rem; color: #9db6cf; margin-top: 2px; }

.nav-group { display: flex; flex-direction: column; gap: 2px; margin-bottom: 18px; }
.nav-group-title {
    font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.08em; color: #6f8daa;
    padding: 10px 12px 6px 12px; font-weight: 600;
}
.nav-item {
    display: flex; align-items: center; gap: 11px;
    padding: 10px 12px; border-radius: var(--radius-sm);
    color: #c6d9ea; text-decoration: none; cursor: pointer;
    font-size: 0.87rem; font-weight: 500;
    border: none; background: transparent; width: 100%; text-align: left;
    transition: background .15s ease, color .15s ease;
    position: relative;
}
.nav-item .nav-icon { font-size: 1rem; width: 20px; text-align: center; flex-shrink: 0; }
.nav-item:hover { background: rgba(255,255,255,0.06); color: #fff; }
.nav-item.active { background: rgba(217,119,6,0.16); color: #fff; }
.nav-item.active::before {
    content: ''; position: absolute; left: -14px; top: 8px; bottom: 8px; width: 3px;
    background: var(--gold-500); border-radius: 4px;
}
.nav-item .nav-badge {
    margin-left: auto; background: var(--gold-500); color: #fff; font-size: 0.65rem;
    padding: 1px 7px; border-radius: 10px; font-weight: 700;
}

.sidebar-footer {
    margin-top: auto; padding: 12px; font-size: 0.72rem; color: #6f8daa; line-height: 1.5;
    border-top: 1px solid rgba(255,255,255,0.08);
}

/* Рекламный баннер в нижней части сайдбара (квадратный) */
.sidebar-ads {
    margin-top: auto; padding: 14px 14px 8px 14px;
    border-top: 1px solid rgba(255,255,255,0.08);
}
.sidebar-ads .ad-box {
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    text-decoration: none; text-align: center;
    width: 100%; height: 210px;
    background: linear-gradient(150deg, #1a3a55 0%, #0f2b45 100%);
    border: 2px solid #d97706;
    border-radius: 12px; padding: 14px 12px;
    box-sizing: border-box;
    box-shadow: 0 4px 16px rgba(0,0,0,0.35), inset 0 0 24px rgba(217,119,6,0.10);
    transition: background .2s ease, border-color .2s ease, transform .15s ease;
}
.sidebar-ads .ad-box:hover { background: linear-gradient(150deg, #21496b 0%, #143652 100%); border-color: #f59e0b; transform: scale(1.02); }
.sidebar-ads .ad-box img {
    display: block; max-width: 100%; max-height: 45%; height: auto;
    border-radius: 8px; margin-bottom: 10px; object-fit: contain;
}
.sidebar-ads .ad-text {
    font-size: 0.84rem; color: #f5e9d0; line-height: 1.5; font-weight: 600;
    display: -webkit-box; -webkit-line-clamp: 5; -webkit-box-orient: vertical; overflow: hidden;
}
.sidebar-ads .ad-cta {
    display: inline-block; margin-top: 10px; font-size: 0.78rem; font-weight: 700;
    color: #f59e0b; letter-spacing: 0.04em;
}

.main {
    display: flex; flex-direction: column; height: 100vh; overflow: hidden; background: var(--slate-50);
}

.topbar {
    height: var(--topbar-h); flex-shrink: 0;
    display: flex; align-items: center; justify-content: space-between;
    padding: 0 28px; background: #fff; border-bottom: 1px solid var(--slate-200);
}
.topbar-title { font-size: 1.05rem; font-weight: 700; color: var(--navy-900); }
.topbar-sub { font-size: 0.78rem; color: var(--slate-500); margin-top: 1px; }
.topbar-actions { display: flex; align-items: center; gap: 10px; }

.content { flex: 1; overflow: hidden; position: relative; }
.view { display: none; height: 100%; overflow-y: auto; padding: 24px 28px 40px 28px; }
.view.active { display: block; }

.btn {
    display: inline-flex; align-items: center; gap: 7px;
    padding: 8px 16px; border-radius: var(--radius-sm); border: 1px solid transparent;
    font-size: 0.83rem; font-weight: 600; cursor: pointer; white-space: nowrap;
    transition: all .15s ease; font-family: inherit;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--navy-900); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--navy-800); }
.btn-accent { background: var(--gold-500); color: #fff; }
.btn-accent:hover:not(:disabled) { background: #b96406; }
.btn-outline { background: #fff; color: var(--navy-900); border-color: var(--slate-300); }
.btn-outline:hover:not(:disabled) { background: var(--slate-100); }
.btn-ghost { background: transparent; color: var(--slate-600); }
.btn-ghost:hover:not(:disabled) { background: var(--slate-100); }
.btn-danger { background: #fff; color: var(--red-700); border-color: #fca5a5; }
.btn-danger:hover:not(:disabled) { background: var(--red-100); }
.btn-sm { padding: 5px 11px; font-size: 0.76rem; border-radius: 7px; }
.btn-icon { padding: 8px; }

.card {
    background: #fff; border: 1px solid var(--slate-200); border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
}
.card-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 16px 20px; border-bottom: 1px solid var(--slate-100);
}
.card-header h3 { margin: 0; font-size: 0.95rem; font-weight: 700; color: var(--navy-900); }
.card-body { padding: 20px; }

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; margin-bottom: 20px; }
.stat-card {
    background: #fff; border: 1px solid var(--slate-200); border-radius: var(--radius-md);
    padding: 16px 18px; box-shadow: var(--shadow-sm);
}
.stat-card .stat-label { font-size: 0.74rem; color: var(--slate-500); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.stat-card .stat-value { font-size: 1.6rem; font-weight: 800; color: var(--navy-900); margin-top: 6px; }
.stat-card .stat-sub { font-size: 0.75rem; color: var(--slate-400); margin-top: 2px; }

.filters { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 18px; align-items: center; }
input, select, textarea {
    font-family: inherit; font-size: 0.85rem; padding: 8px 12px;
    border: 1px solid var(--slate-300); border-radius: var(--radius-sm); background: #fff; color: var(--slate-800);
}
input:focus, select:focus, textarea:focus {
    outline: none; border-color: var(--navy-700); box-shadow: 0 0 0 3px rgba(11,43,74,0.1);
}
label { font-size: 0.8rem; font-weight: 600; color: var(--slate-700); display: block; margin-bottom: 4px; }

.table-wrap { border: 1px solid var(--slate-200); border-radius: var(--radius-md); overflow: hidden; background: #fff; }
table.data-table { width: 100%; border-collapse: collapse; font-size: 0.83rem; }
table.data-table thead th {
    position: sticky; top: 0; background: var(--slate-50); color: var(--slate-600);
    font-weight: 700; text-align: left; padding: 11px 14px; border-bottom: 1px solid var(--slate-200);
    font-size: 0.72rem; text-transform: uppercase; letter-spacing: .04em;
}
table.data-table td { padding: 10px 14px; border-bottom: 1px solid var(--slate-100); vertical-align: middle; }
table.data-table tbody tr:last-child td { border-bottom: none; }
table.data-table tbody tr:hover { background: var(--slate-50); }
tr.row-clickable { cursor: pointer; }
tr.row-detail { background: var(--slate-50); }
tr.row-detail td { padding: 0; }
tr.row-detail .detail-inner { padding: 14px 20px 18px 20px; }
tr.row-detail:not(.show) { display: none; }

.badge {
    display: inline-flex; align-items: center; gap: 4px; padding: 3px 10px; border-radius: 30px;
    font-size: 0.72rem; font-weight: 700; white-space: nowrap;
}
.badge-gray  { background: var(--gray-100);  color: var(--gray-700); }
.badge-amber { background: var(--amber-100); color: var(--amber-700); }
.badge-green  { background: var(--green-100);  color: var(--green-700); }
.badge-red    { background: var(--red-100);    color: var(--red-700); }
.badge-blue   { background: var(--blue-100);   color: var(--blue-700); }
.badge-yellow { background: var(--amber-100);  color: var(--amber-700); }

/* Defects: highlight rows awaiting remake */
tr.row-highlight-warn td { background: #fffbeb; }
tr.row-highlight-warn:hover td { background: #fef3c7; }

/* Info banner for defects summary */
.info-banner { padding: 8px 14px; border-radius: 8px; font-size: 0.88rem; }
.info-banner.warn { background: #fffbeb; border: 1px solid #fcd34d; color: #92400e; }

.empty-state { text-align: center; padding: 60px 20px; color: var(--slate-500); }
.empty-state .icon { font-size: 2.6rem; margin-bottom: 10px; }
.empty-state h3 { color: var(--slate-800); font-size: 1.05rem; margin: 0 0 6px 0; }
.loading-row { text-align: center; padding: 40px 0; color: var(--slate-500); }

.pagination { display: flex; gap: 6px; justify-content: center; margin-top: 16px; }
.pagination button {
    padding: 5px 12px; border: 1px solid var(--slate-300); border-radius: 7px; background: #fff;
    cursor: pointer; font-size: 0.8rem; color: var(--slate-700);
}
.pagination button.active { background: var(--navy-900); color: #fff; border-color: var(--navy-900); }

.chat-shell { display: flex; flex-direction: column; height: 100%; }
.chat-toolbar { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.chat-messages {
    flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 14px;
    padding: 4px 4px 14px 4px; margin-bottom: 12px;
}
.msg { display: flex; max-width: 78%; }
.msg.user { align-self: flex-end; }
.msg.bot { align-self: flex-start; }
.msg .bubble {
    padding: 12px 16px; border-radius: 16px; line-height: 1.55; font-size: 0.88rem;
    box-shadow: var(--shadow-sm);
}
.msg.user .bubble { background: var(--navy-900); color: #fff; border-bottom-right-radius: 4px; }
.msg.bot .bubble { background: #fff; border: 1px solid var(--slate-200); color: var(--slate-800); border-bottom-left-radius: 4px; }
.bubble table { border-collapse: collapse; width: 100%; margin: 10px 0; font-size: 0.82rem; }
.bubble th { background: var(--slate-100); padding: 6px 10px; text-align: left; font-weight: 700; }
.bubble td { padding: 6px 10px; border-bottom: 1px solid var(--slate-100); }
.bubble h3 { margin: 10px 0 6px 0; font-size: 0.98rem; color: var(--navy-900); }
.bubble ul { margin: 6px 0 8px 20px; }
.bubble strong { color: var(--navy-900); }

.chat-input-row { display: flex; gap: 10px; }
.chat-input-row input {
    flex: 1; padding: 12px 16px; border-radius: 26px; border: 1px solid var(--slate-300); font-size: 0.87rem;
}
.chat-input-row button {
    padding: 10px 22px; border-radius: 26px; border: none; background: var(--navy-900); color: #fff;
    font-weight: 700; cursor: pointer; font-size: 0.85rem;
}
.chat-input-row button:hover { background: var(--navy-800); }
.chat-typing { font-size: 0.78rem; color: var(--slate-400); font-style: italic; padding-left: 4px; }

.modal-overlay {
    display: none; position: fixed; inset: 0; background: rgba(15,23,42,0.45);
    backdrop-filter: blur(3px); z-index: 2000; align-items: center; justify-content: center; padding: 24px;
}
.modal-overlay.active { display: flex; }
.modal-box {
    background: #fff; border-radius: var(--radius-lg); box-shadow: var(--shadow-lg);
    width: 100%; max-width: 640px; max-height: 88vh; overflow-y: auto; padding: 26px 30px;
}
.modal-box.wide { max-width: 960px; }
.modal-box h2 { margin: 0 0 18px 0; font-size: 1.15rem; color: var(--navy-900); }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 22px; }

.slideover-overlay {
    display: none; position: fixed; inset: 0; background: rgba(15,23,42,0.35); z-index: 1800;
}
.slideover-overlay.active { display: block; }
.slideover {
    position: fixed; top: 0; right: -420px; width: 400px; height: 100vh; background: #fff;
    box-shadow: var(--shadow-lg); z-index: 1900; transition: right .25s ease; display: flex; flex-direction: column;
}
.slideover.active { right: 0; }
.slideover-header { padding: 20px 22px; border-bottom: 1px solid var(--slate-200); display: flex; justify-content: space-between; align-items: center; }
.slideover-header h3 { margin: 0; font-size: 1rem; color: var(--navy-900); }
.slideover-body { padding: 20px 22px; overflow-y: auto; flex: 1; }
.price-row { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.price-row label { width: 66px; margin: 0; flex-shrink: 0; }
.price-row input { flex: 1; }

#toast-container { position: fixed; bottom: 22px; right: 22px; z-index: 3000; display: flex; flex-direction: column; gap: 10px; }
.toast {
    background: var(--slate-900); color: #fff; padding: 12px 18px; border-radius: var(--radius-sm);
    box-shadow: var(--shadow-lg); font-size: 0.83rem; min-width: 240px; max-width: 380px;
    animation: toast-in .2s ease; display: flex; align-items: center; gap: 8px;
}
.toast.success { background: #14532d; }
.toast.error { background: #7f1d1d; }
.toast.warning { background: #78350f; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

.muted { color: var(--slate-500); }
.text-sm { font-size: 0.8rem; }
.mt-2 { margin-top: 8px; } .mt-3 { margin-top: 14px; } .mb-2 { margin-bottom: 8px; }
.flex { display: flex; } .flex-col { display: flex; flex-direction: column; }
.gap-2 { gap: 8px; } .gap-3 { gap: 12px; }
.items-center { align-items: center; } .justify-between { justify-content: space-between; }
hr.sep { border: none; border-top: 1px solid var(--slate-200); margin: 16px 0; }

.remove-btn {
    background: var(--red-100); color: var(--red-700); border: none; border-radius: 6px;
    padding: 3px 9px; cursor: pointer; font-size: 0.78rem; font-weight: 700;
}
.remove-btn:hover { background: #fecaca; }

@media (max-width: 980px) {
    :root { --sidebar-w: 210px; }
    .view { padding: 18px; }
    .topbar { padding: 0 18px; }
}
