/* ========== Theme toggle ========== */
.theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 8px;
  border: 1px solid var(--color-border);
  background: transparent;
  color: var(--color-muted);
  cursor: pointer;
  flex-shrink: 0;
  transition: all 0.15s;
}
.theme-toggle:hover { color: var(--color-text); background: var(--color-hover); border-color: var(--color-border-strong); }
.theme-toggle svg { width: 16px; height: 16px; }
.theme-toggle .icon-moon { display: none; }
html[data-theme="light"] .theme-toggle .icon-sun { display: none; }
html[data-theme="light"] .theme-toggle .icon-moon { display: block; }

/* ========== Base ========== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif; background: var(--color-bg); color: var(--color-text); }

.app-sidebar a, .overlay-sidebar a { color: inherit; text-decoration: none; }

.hidden { display: none; }

/* Page routing */
.page { display: none; }
.page.active { display: block; }
#page-auth.active {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--color-bg);
}

/* ========== App layout ========== */
#page-app { display: flex; min-height: 100vh; }
#page-app.hidden { display: none; }
.app-sidebar { width: 256px; background: var(--color-panel); color: var(--color-text); display: flex; flex-direction: column; flex-shrink: 0; }
.app-main { flex: 1; display: flex; flex-direction: column; min-height: 100vh; }
.app-topbar { display: flex; align-items: center; justify-content: space-between; min-height: 80px; padding: 12px 24px; border-bottom: 1px solid var(--color-border); background: var(--color-panel); }
.app-topbar * { color: var(--color-text-secondary); }
.app-content { flex: 1; padding: 24px; overflow-y: auto; }
.app-mobile-header { display: none; }
@media (max-width: 767px) {
  .app-sidebar { display: none; }
  .app-mobile-header { display: flex; position: fixed; top: 0; left: 0; right: 0; z-index: 40; background: var(--color-panel); color: var(--color-text); padding: 12px 16px; align-items: center; justify-content: space-between; }
  .app-main { padding-top: 56px; }
  .app-topbar { display: none; }
}
/* Desktop: sidebar stays on screen, only the content area scrolls */
@media (min-width: 768px) {
  #page-app { height: 100vh; overflow: hidden; }
  .app-main { height: 100vh; overflow: hidden; }
  .app-content { min-height: 0; }
}
.user-avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--color-accent); display: flex; align-items: center; justify-content: center; color: var(--color-white); font-size: 0.875rem; font-weight: 700; }

/* Modal overlay */
#modal-overlay { position: fixed; inset: 0; z-index: 50; background: rgba(0,0,0,0.5); display: flex; align-items: center; justify-content: center; padding: 16px; }
#modal-overlay.hidden { display: none; }
.modal-box { background: var(--color-card); border-radius: 12px; box-shadow: var(--color-modal-shadow); width: 100%; max-width: 32rem; max-height: 85vh; overflow-y: auto; }
.modal-header { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--color-border); }
.modal-header h2 { font-size: 1.25rem; font-weight: 600; color: var(--color-text); }
.modal-body { padding: 20px; }

/* Mobile sidebar overlay */
.mobile-sidebar-overlay { position: fixed; inset: 0; z-index: 50; }
.mobile-sidebar-overlay .overlay-bg { position: absolute; inset: 0; background: rgba(0,0,0,0.5); }
.mobile-sidebar-overlay .overlay-sidebar { position: absolute; top: 0; left: 0; bottom: 0; width: 256px; background: var(--color-panel); color: var(--color-text); display: flex; flex-direction: column; }

/* ========== Sidebar ========== */
#sidebar-nav { flex: 1; overflow-y: auto; padding: 16px 12px; }
#sidebar-nav-mobile { flex: 1; overflow-y: auto; padding: 16px 12px; }
.app-sidebar .p-5 { padding: 20px; }
.app-sidebar .border-b { border-bottom: 1px solid var(--color-border); }
.app-sidebar .flex { display: flex; }
.app-sidebar .items-center { align-items: center; }
.app-sidebar .gap-3 { gap: 12px; }
.app-sidebar .flex-1 { flex: 1; }
.app-sidebar .size-10 { width: 40px; height: 40px; }
.app-sidebar .rounded-lg { border-radius: 8px; }
.app-sidebar .bg-red-600 { background: #dc2626; }
.app-sidebar .text-white { color: var(--color-white); }
.app-sidebar .font-bold { font-weight: 700; }
.app-sidebar .text-lg { font-size: 1.25rem; }
.app-sidebar .text-sm { font-size: 0.875rem; }
.app-sidebar .text-xs { font-size: 0.75rem; }
.app-sidebar .text-gray-400 { color: var(--color-muted); }
.app-sidebar .px-3 { padding-left: 12px; padding-right: 12px; }
.app-sidebar .py-4 { padding-top: 16px; padding-bottom: 16px; }
.app-sidebar .space-y-1 > * + * { margin-top: 4px; }
.app-sidebar .overflow-y-auto { overflow-y: auto; }
.app-sidebar .py-2 { padding-top: 8px; padding-bottom: 8px; }
.app-sidebar .mt-4 { margin-top: 16px; }
.app-sidebar .pt-3 { padding-top: 12px; }
.app-sidebar .mt-3 { margin-top: 12px; }
.app-sidebar .px-3 { padding-left: 12px; padding-right: 12px; }
.app-sidebar .py-3 { padding-top: 12px; padding-bottom: 12px; }
.app-sidebar .mt-2 { margin-top: 8px; }
.app-sidebar .gap-3 { gap: 12px; }
.app-sidebar .size-8 { width: 32px; height: 32px; }
.app-sidebar .rounded-full { border-radius: 50%; }
.app-sidebar .bg-blue-600 { background: var(--color-accent); }
.app-sidebar .text-sm { font-size: 0.875rem; }
.app-sidebar .font-medium { font-weight: 500; }
.app-sidebar .tracking-wider { letter-spacing: 0.05em; }
.app-sidebar .uppercase { text-transform: uppercase; }
.app-sidebar .font-semibold { font-weight: 600; }
.app-sidebar .text-gray-500 { color: var(--color-muted); }
.app-sidebar .border-t { border-top: 1px solid var(--color-border); }
.overlay-sidebar .p-5 { padding: 20px; }
.overlay-sidebar .border-b { border-bottom: 1px solid var(--color-border); }
.overlay-sidebar .flex { display: flex; }
.overlay-sidebar .items-center { align-items: center; }
.overlay-sidebar .gap-3 { gap: 12px; }
.overlay-sidebar .size-10 { width: 40px; height: 40px; }
.overlay-sidebar .rounded-lg { border-radius: 8px; }
.overlay-sidebar .bg-red-600 { background: #dc2626; }
.overlay-sidebar .text-white { color: var(--color-white); }
.overlay-sidebar .font-bold { font-weight: 700; }
.overlay-sidebar .text-lg { font-size: 1.25rem; }
.overlay-sidebar .text-sm { font-size: 0.875rem; }
.overlay-sidebar .text-xs { font-size: 0.75rem; }
.overlay-sidebar .text-gray-400 { color: var(--color-muted); }
.overlay-sidebar .text-gray-500 { color: var(--color-muted); }
.overlay-sidebar .size-8 { width: 32px; height: 32px; }
.overlay-sidebar .rounded-full { border-radius: 50%; }
.overlay-sidebar .bg-blue-600 { background: var(--color-accent); }
.overlay-sidebar .font-medium { font-weight: 500; }
.overlay-sidebar .border-t { border-top: 1px solid var(--color-border); }
.overlay-sidebar .px-3 { padding-left: 12px; padding-right: 12px; }
.overlay-sidebar .py-3 { padding-top: 12px; padding-bottom: 12px; }
.overlay-sidebar .mt-2 { margin-top: 8px; }
.sidebar-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--color-muted);
  text-decoration: none;
  transition: all 0.15s;
}
.sidebar-link:hover { color: var(--color-text); background: var(--color-hover); }
.sidebar-link.active { color: var(--color-text); background: var(--color-active); }

/* ========== Buttons ========== */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 18px;
  border: none;
  border-radius: 8px;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
  text-decoration: none;
  line-height: 1.4;
}
.btn-primary { background: var(--color-accent); color: white; }
.btn-primary:hover { background: var(--color-accent-hover); }
.btn-outline { background: transparent; color: var(--color-text-secondary); border: 1px solid var(--color-border-strong); }
.btn-outline:hover { background: var(--color-hover); }
.btn-danger { background: var(--color-danger); color: white; }
.btn-danger:hover { background: var(--color-danger-hover); }
.btn-text-danger { background: none; color: var(--color-danger-text); padding: 4px 8px; font-size: 0.875rem; cursor: pointer; }
.btn-text-danger:hover { background: var(--badge-red-strong-bg); color: var(--color-danger-bright); }
.btn-sm { padding: 4px 12px; font-size: 0.75rem; }
.detail-header .btn-add { min-width: 110px; justify-content: center; }
.btn-success { background: var(--color-success); color: white; }
.btn-warning { background: var(--color-warning); color: white; }
.btn-close { background: none; border: none; font-size: 1.5rem; cursor: pointer; color: var(--color-muted); padding: 4px; line-height: 1; }
.btn-close:hover { color: var(--color-text-secondary); }

/* ========== Status badges ========== */
.status-badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 12px;
  font-size: 0.75rem;
  font-weight: 600;
  white-space: nowrap;
}
.status-ожидается { background: var(--color-border); color: var(--color-text-secondary); border: 1px solid var(--color-border-strong); }
.status-выполняется { background: var(--badge-blue-bg); color: var(--color-accent-text); border: 1px solid var(--badge-blue-border); }
.status-завершен { background: var(--badge-green-bg); color: var(--color-success-text); border: 1px solid var(--badge-green-border); }
.status-аванс { background: var(--badge-amber-bg); color: var(--color-warning-text); border: 1px solid var(--badge-amber-border); }
.status-оплачена { background: var(--badge-green-bg); color: var(--color-success-text); border: 1px solid var(--badge-green-border); }
.status-paused { background: var(--badge-amber-bg); color: var(--color-warning-text); border: 1px solid var(--badge-amber-border); }
.delay-badge { display: inline-block; padding: 2px 10px; border-radius: 12px; font-size: 0.75rem; font-weight: 600; background: var(--badge-red-bg); color: var(--color-danger-bright); border: 1px solid var(--badge-red-border); }
.delay-none { background: var(--badge-green-bg); color: var(--color-success-text); border: 1px solid var(--badge-green-border); }

/* ========== Documents ========== */
.doc-name { font-weight: 500; color: var(--color-text); word-break: break-all; }
.doc-actions { white-space: nowrap; }
.documents-table td:first-child { white-space: nowrap; }

/* ========== Cards ========== */
.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(360px, 1fr)); gap: 16px; }
.card {
  background: var(--color-card); border: 1px solid var(--color-border); border-radius: 12px; padding: 20px;
  cursor: pointer; transition: all 0.15s;
}
.card:hover { box-shadow: var(--color-card-shadow); border-color: var(--color-accent-soft); }
.card-title { font-size: 1.25rem; font-weight: 600; margin-bottom: 12px; color: var(--color-text); }
.card-body { font-size: 0.875rem; color: var(--color-muted); }
.card-body > div { margin-bottom: 4px; }
.card-footer { margin-top: 12px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

/* Dashboard KPI cards */
.dashboard-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 16px; margin-bottom: 24px; }
.kpi-card, .dash-card {
  background: var(--color-card); border: 1px solid var(--color-border); border-radius: 12px; padding: 20px;
  transition: border-color 0.2s;
}
.kpi-card:hover, .dash-card:hover { border-color: var(--color-accent-soft); }
.kpi-label, .dash-card-label { font-size: 0.75rem; font-weight: 600; color: var(--color-muted); text-transform: uppercase; letter-spacing: 0.04em; margin-bottom: 8px; }
.kpi-value, .dash-card-value { font-size: 1.5rem; font-weight: 700; line-height: 1.2; color: var(--color-text); }
.kpi-desc, .dash-card-sub { font-size: 0.75rem; color: var(--color-muted); margin-top: 4px; }
.kpi-value-green { color: var(--color-success); }
.kpi-value-red { color: var(--color-danger-text); }
/* ========== Tables ========== */
table { width: 100%; border-collapse: collapse; background: var(--color-card); border-radius: 12px; overflow: hidden; border: 1px solid var(--color-border); }
th, td { padding: 10px 14px; text-align: left; border-bottom: 1px solid var(--color-border); font-size: 0.875rem; color: var(--color-text-secondary); }
th { background: var(--color-border); font-weight: 600; color: var(--color-text-secondary); }
tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--color-row-hover); }

/* Inset tables inside cards blend with the card surface (no double frame/corners) */
.detail-section .table-scroll table,
.work-stage-card .table-scroll table {
  background: transparent;
  border: none;
  border-radius: 0;
  overflow: visible;
}

/* ========== Forms ========== */
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 0.875rem; font-weight: 500; color: var(--color-text-secondary); margin-bottom: 4px; }
.form-control { width: 100%; padding: 8px 12px; border: 1px solid var(--color-input-border); border-radius: 8px; font-size: 0.875rem; transition: border-color 0.15s; background: var(--color-input-bg); color: var(--color-text); }
.form-control:focus { outline: none; border-color: var(--color-accent-soft); box-shadow: 0 0 0 3px var(--color-focus-ring); }
select.form-control { appearance: auto; }
textarea.form-control { resize: vertical; min-height: 90px; font-family: inherit; line-height: 1.5; }
.comment-status { font-size: 12px; font-weight: 600; color: var(--color-muted); }
.comment-status.saving { color: var(--color-accent-text); }
.comment-status.saved { color: var(--color-success-text); }
.comment-status.pending { color: var(--color-accent-soft); }
.comment-status.error { color: var(--color-danger-text); }
.form-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }

/* ========== Detail section ========== */
.detail-section { background: var(--color-card); border: 1px solid var(--color-border); border-radius: 12px; padding: 20px; margin-bottom: 32px; }
.detail-section h2 { font-size: 1.125rem; font-weight: 600; margin-bottom: 16px; color: var(--color-text); }
.detail-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; }
.detail-item label { display: block; font-size: 0.75rem; color: var(--color-muted); margin-bottom: 2px; }
.detail-item span { font-size: 1rem; font-weight: 500; color: var(--color-text); }

/* ========== Object detail: accordion (desktop) + tabs (mobile) ========== */
.obj-tabs { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 16px; overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
.obj-tabs::-webkit-scrollbar { display: none; }
.obj-tab {
  display: inline-flex; align-items: center; gap: 6px; flex-shrink: 0;
  padding: 7px 14px; border: 1px solid var(--color-border); border-radius: 999px;
  background: var(--color-card); color: var(--color-text-secondary);
  font-size: 0.875rem; font-weight: 500; cursor: pointer; white-space: nowrap;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.obj-tab:hover { border-color: var(--color-border-strong); }
.obj-tab.active { background: var(--color-accent); border-color: var(--color-accent); color: var(--color-white); }
.tab-count {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 18px; height: 18px; padding: 0 5px; border-radius: 999px;
  font-size: 0.75rem; font-weight: 700; background: var(--color-border); color: var(--color-text-secondary);
}
.obj-tab.active .tab-count { background: rgba(255,255,255,0.25); color: var(--color-white); }
.section-head { cursor: pointer; user-select: none; }
.section-head:hover { border-radius: 6px; background: var(--color-hover); }
.section-title { display: flex; align-items: center; gap: 8px; flex: 1; margin: 0; }
.section-title .chev { font-size: 0.96rem; color: var(--color-muted); transition: transform 0.2s; }
.obj-section.collapsed .section-title .chev { transform: rotate(-90deg); }
.obj-section.collapsed .section-body { display: none; }
@media (max-width: 767px) {
  .obj-tabs {
    display: flex; flex-wrap: wrap;
    position: sticky; top: 56px; z-index: 30;
    margin: 0 0 16px; padding: 8px 0;
    background: var(--color-panel);
    max-width: 100%; min-width: 0; overflow-x: hidden;
  }
  .app-main { min-width: 0; }
  .obj-section, .table-scroll { max-width: 100%; min-width: 0; }
}

/* ========== Layout utilities ========== */
.detail-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.detail-header h2 { border: none; padding: 0; margin: 0; }
.btn-row { display: flex; gap: 6px; }
.summary-row { margin-bottom: 12px; display: flex; gap: 12px; flex-wrap: wrap; }
.mt-3 { margin-top: 12px; }
.mt-0 { margin-top: 0; }
.hint { font-size: 0.75rem; }

/* ========== Workers ========== */
.worker-card {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--color-card); border: 1px solid var(--color-border); border-radius: 12px; padding: 14px 20px; margin-bottom: 8px;
}
.worker-card:hover { border-color: var(--color-border-strong); }
.worker-card-name { font-weight: 500; color: var(--color-text); }
.worker-card-count { font-size: 0.875rem; color: var(--color-muted); }

/* Worker items in objects */
.worker-item { display: flex; align-items: center; justify-content: space-between; padding: 8px 0; border-bottom: 1px solid var(--color-border); }
.worker-item:last-child { border-bottom: none; }

/* Salary */
.salary-row { background: var(--color-salary-bg); }
.salary-row td { opacity: 0.85; }
.salary-badge { display: inline-block; font-size: 0.75rem; background: var(--color-salary-badge-bg); color: var(--color-salary-badge-text); padding: 1px 6px; border-radius: 4px; margin-left: 4px; font-weight: 600; }

/* ========== Finance table ========== */
.finance-table { min-width: 600px; }
.finance-table th.num, .finance-table td.num { text-align: right; white-space: nowrap; }
.finance-table th { background: var(--color-border); font-weight: 600; font-size: 0.875rem; }
.finance-table tfoot th, .finance-table tfoot td { border-top: 2px solid var(--color-border-strong); font-weight: 700; background: var(--color-panel); }
.finance-link { color: var(--color-accent-soft); text-decoration: none; font-weight: 500; }
.finance-link:hover { text-decoration: underline; }

/* ========== Stage timeline ========== */
.stage-name { font-weight: 500; }
.stage-name.active { color: var(--color-accent-soft); }
.stage-actions { display: flex; gap: 4px; justify-content: flex-end; width: 100%; }

/* ========== Work stages (Этап -> виды работ) ========== */
.work-stages { display: flex; flex-direction: column; gap: 16px; }
.work-stage-card { padding: 0; border: none; background: transparent; }
.work-stage-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 10px; flex-wrap: wrap; }
.work-stage-title { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.work-stage-sub { display: flex; gap: 16px; font-size: 0.875rem; margin-bottom: 10px; }
.works-table { width: 100%; border-collapse: collapse; font-size: 0.875rem; }
.works-table th { text-align: left; padding: 6px 10px; font-weight: 600; color: var(--color-muted); font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.04em; border-bottom: 1px solid var(--color-border); background: var(--color-panel); }
.works-table th.col-date { width: 170px; }
.works-table th.col-status { width: 150px; }
.works-table .work-status { font-size: 0.875rem; padding: 2px 6px; width: 130px; }
.works-table th.col-actions { width: 36px; }
.works-table td { padding: 4px 10px; border-bottom: 1px solid var(--color-border); color: var(--color-text-secondary); vertical-align: middle; }
.works-table tbody tr.dragging { opacity: 0.45; }
.works-table tbody tr.over { border-color: var(--color-accent-soft); }
.works-table td.col-name .work-grip { color: var(--color-muted); font-size: 0.8rem; margin-right: 6px; }
.works-table .work-name { font-size: 0.875rem; color: var(--color-text-secondary); }
.works-table td.col-name { width: 40%; }
.work-rename { font-size: 0.875rem; padding: 2px 8px; width: 100%; }
.work-date { font-size: 0.875rem; padding: 4px 6px; border: 1px solid var(--color-border); border-radius: 6px; background: var(--color-input); color: var(--color-text); width: 140px; }
.works-empty-row td { font-size: 0.875rem; color: var(--color-muted); font-style: italic; padding: 10px; }
.work-del { opacity: 0.6; }
.work-del:hover { opacity: 1; }
.work-stage-foot { margin-top: 12px; }

/* ========== Page content ========== */
.app-content h1 { font-size: 1.25rem; font-weight: 700; color: var(--color-text); }
@media (min-width: 768px) {
  .app-content h1 { font-size: 1.5rem; }
}
.app-content .flex { display: flex; }
.app-content .items-center { align-items: center; }
.app-content .justify-between { justify-content: space-between; }
.app-content .mb-4 { margin-bottom: 16px; }
.app-content .mb-3 { margin-bottom: 12px; }
.app-content .gap-2 { gap: 8px; }
.app-content .gap-3 { gap: 12px; }
.app-content .mt-6 { margin-top: 24px; }
.app-content .p-4 { padding: 16px; }
.app-content .flex-1 { flex: 1; }
/* ========== Table ========== */
.table-wrap { overflow-x: auto; background: var(--color-card); border-radius: 8px; border: 1px solid var(--color-border); }
.detail-section-title { font-size: 1.25rem; font-weight: 600; margin-bottom: 8px; color: var(--color-text); }
.data-table { width: 100%; border-collapse: collapse; font-size: 0.875rem; }
.data-table th { text-align: left; padding: 10px 14px; font-weight: 600; color: var(--color-muted); font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.04em; border-bottom: 1px solid var(--color-border); background: var(--color-panel); }
.data-table td { padding: 10px 14px; border-bottom: 1px solid var(--color-border); color: var(--color-text-secondary); }
.data-table tbody tr:hover { background: var(--color-panel); }
.data-table .num { text-align: right; font-variant-numeric: tabular-nums; }

/* ========== Client Access Section ========== */
.client-access-section { border-top: 1px solid var(--color-border); padding-top: 16px; margin-top: 8px; }
.client-access-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.client-access-title { font-size: 0.875rem; font-weight: 600; color: var(--color-text); }
.client-access-info { font-size: 0.75rem; color: var(--color-muted); }
.password-generated { background: var(--color-password-bg); border: 1px solid var(--color-password-border); border-radius: 8px; padding: 12px; margin-top: 4px; }
.password-label { font-size: 0.75rem; color: var(--color-text-secondary); margin-bottom: 4px; }
.password-value { font-family: monospace; font-size: 1.25rem; font-weight: 700; letter-spacing: 0.1em; padding: 6px 8px; background: var(--color-password-value-bg); border: 1px dashed var(--color-password-border); border-radius: 4px; display: inline-block; cursor: pointer; user-select: all; color: var(--color-text); }
.password-hint { font-size: 0.75rem; color: var(--color-password-hint); margin-top: 6px; }
.toggle-switch { position: relative; display: inline-block; width: 40px; height: 22px; flex-shrink: 0; }
.toggle-switch input { opacity: 0; width: 0; height: 0; }
.toggle-slider { position: absolute; inset: 0; background: var(--color-toggle); border-radius: 22px; cursor: pointer; transition: 0.2s; }
.toggle-slider::before { content: ''; position: absolute; left: 3px; top: 3px; width: 16px; height: 16px; background: var(--color-white); border-radius: 50%; transition: 0.2s; }
.toggle-switch input:checked + .toggle-slider { background: var(--color-toggle-checked); }
.toggle-switch input:checked + .toggle-slider::before { transform: translateX(18px); }
.btn-xs { padding: 4px 10px; font-size: 0.75rem; }

/* ========== Utility ========== */
.text-muted { color: var(--color-muted); font-size: 0.875rem; }
.data-table td.text-delay, td.text-delay { color: var(--color-danger-text); font-weight: 600; }
.data-table td.text-ok, td.text-ok { color: var(--color-success); }
.empty-state { text-align: center; padding: 48px 24px; color: var(--color-muted); }
.empty-state p { margin-bottom: 16px; }
.empty-state-icon { margin: 0 auto 12px; display: block; color: var(--color-border-strong); }
.empty-state .btn { margin-top: 8px; }
.tabs { display: flex; gap: 0; border-bottom: 2px solid var(--color-border); margin-bottom: 16px; }
.tab-btn { padding: 10px 20px; border: none; background: none; cursor: pointer; font-size: 1rem; color: var(--color-muted); border-bottom: 2px solid transparent; margin-bottom: -2px; transition: color 0.2s, border-color 0.2s; }
.tab-btn:hover { color: var(--color-tab-hover); }
.tab-btn.active { color: var(--color-text); border-bottom-color: var(--color-text); font-weight: 600; }
.tab-content { display: none; }
.tab-content.active { display: block; }
.list-info { display: flex; gap: 16px; margin-bottom: 16px; font-size: 0.875rem; color: var(--color-muted); }
.list-info-item { padding: 4px 12px; background: var(--color-card); border-radius: 6px; }
.list-info-item.overdue { background: var(--badge-red-strong-bg); color: var(--color-danger-soft); font-weight: 600; }
.label { color: var(--color-muted); font-size: 0.75rem; }

/* Inline edit */
.inline-edit { display: flex; align-items: center; gap: 6px; }
.inline-edit select, .inline-edit input { padding: 4px 8px; border: 1px solid var(--color-input-border); border-radius: 4px; font-size: 0.875rem; background: var(--color-input-bg); color: var(--color-text); }

/* Table scroll */
.table-scroll { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table-scroll table { width: 100%; max-width: 100%; }

/* Workers table specific */
.workers-table th:last-child, .workers-table td:last-child { text-align: right; }
.payments-table th:last-child, .payments-table td:last-child { text-align: right; }
.table-compact td, .table-compact th { padding: 8px 10px; }

/* Worker table inputs */
.workers-table .work-desc-input { min-width: 120px; max-width: 200px; }
.workers-table .amount-input { width: 100px; }
.workers-table .status-select { width: 130px; }
.workers-table .date-input { width: 140px; }

/* ========== Progress bar ========== */
.progress-bar { height: 8px; background: var(--color-border); border-radius: 4px; overflow: hidden; }
.progress-bar-fill { height: 100%; border-radius: 4px; transition: width 0.3s; }

/* ========== Responsive ========== */
@media (max-width: 768px) {
  .card-grid { grid-template-columns: 1fr; gap: 12px; }
  .card { padding: 14px; }
  .detail-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .detail-section { padding: 14px; }
  table { font-size: 0.75rem; }
  th, td { padding: 6px 8px; }
  .worker-card { flex-direction: column; align-items: flex-start; gap: 8px; }
  .dashboard-cards { grid-template-columns: repeat(2, 1fr); gap: 10px; }
}
@media (max-width: 767px) {
  .table-scroll table, .table-scroll table.finance-table, .table-scroll table.workers-table, .table-scroll table.payments-table, .table-scroll table.works-table { min-width: 0; width: 100%; }
  .table-scroll table thead { display: none; }
  .table-scroll table td { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 8px 10px; border-bottom: 1px solid var(--color-border); white-space: normal; word-break: break-word; }
  .table-scroll table td::before { content: attr(data-label); font-weight: 600; color: var(--color-muted); flex-shrink: 0; margin-right: 8px; }
  .table-scroll table td.num { justify-content: space-between; white-space: normal; }
  .table-scroll table td:empty { display: none; }
  .table-scroll table tr { display: block; margin-bottom: 10px; border: 1px solid var(--color-border-strong); border-radius: 8px; overflow: hidden; background: var(--color-card); }
  .table-scroll table td, .table-scroll table th { width: auto !important; min-width: 0; }
  .table-scroll table tfoot { display: block; }
  .table-scroll table tfoot tr { display: block; margin-bottom: 0; }
  .table-scroll table tfoot th, .table-scroll table tfoot td { display: flex; justify-content: space-between; align-items: center; gap: 8px; border-bottom: none; }
  .table-scroll table tfoot th::before { content: attr(data-label); font-weight: 600; color: var(--color-muted); flex-shrink: 0; margin-right: 8px; }
  .table-scroll { overflow-x: visible; }
  .table-scroll table td.col-name { justify-content: flex-start; }
  .table-scroll table td.col-name .work-grip { flex-shrink: 0; }
  .table-scroll table td.col-name .work-name { flex: 1 1 auto; min-width: 0; word-break: break-word; white-space: normal; }
}
@media (max-width: 480px) {
  .dashboard-cards { grid-template-columns: 1fr; }
  .btn { padding: 8px 14px; font-size: 0.875rem; min-height: 40px; padding: 8px 12px; }
  .btn-sm { padding: 6px 10px; font-size: 0.75rem; min-height: 34px; }
  .status-badge, .delay-badge { font-size: 0.75rem; padding: 2px 8px; }
  .empty-state { padding: 32px 16px; }
}

/* Auth role grid + login modal */
.modal-overlay { position: fixed; inset: 0; z-index: 60; background: rgba(0,0,0,0.5); display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal-overlay.hidden { display: none; }
.auth-modal-box { padding: 22px; }
.modal-close { background: none; border: none; font-size: 1.5rem; line-height: 1; color: var(--color-text-secondary); cursor: pointer; padding: 0 4px; }
.role-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.role-card { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; padding: 18px 12px; border: 1px solid var(--color-border); border-radius: 12px; background: var(--color-card); color: var(--color-text); cursor: pointer; transition: border-color .15s, box-shadow .15s, transform .05s; }
.role-card:hover { border-color: var(--color-accent); box-shadow: 0 4px 14px rgba(0,0,0,.08); }
.role-card:active { transform: translateY(1px); }
.role-card-icon { width: 34px; height: 34px; color: var(--color-accent); }
.role-card-icon svg { width: 100%; height: 100%; }
.role-card-label { font-size: 0.95rem; font-weight: 600; }
@media (max-width: 480px) {
  .role-grid { gap: 10px; }
  .role-card { padding: 14px 8px; }
}

/* ========== Object media gallery ========== */
.media-filters { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.media-filter-chip {
  padding: 6px 14px; border-radius: 999px; border: 1px solid var(--color-border-strong);
  background: var(--color-card); color: var(--color-text-secondary); font-size: 0.75rem; cursor: pointer; transition: all 0.15s;
}
.media-filter-chip:hover { background: var(--color-hover); }
.media-filter-chip.active { background: var(--color-accent); border-color: var(--color-accent); color: var(--color-white); }
.media-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 16px; }
.media-card { background: var(--color-card); border: 1px solid var(--color-border); border-radius: 12px; overflow: hidden; transition: border-color 0.15s; }
.media-card:hover { border-color: var(--color-accent-soft); }
.media-thumb {
  width: 100%; aspect-ratio: 4 / 3; background-color: var(--color-panel); background-size: cover; background-position: center;
  display: flex; align-items: center; justify-content: center; cursor: zoom-in; position: relative;
}
.media-thumb-fallback { font-size: 2rem; opacity: 0.6; line-height: 1; }
.media-video { background: linear-gradient(135deg, var(--color-border), var(--color-panel)); }
.media-play {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  color: var(--color-white); font-size: 2rem; text-shadow: 0 1px 6px rgba(0,0,0,.45);
}
.media-meta { padding: 10px 12px; display: flex; flex-direction: column; gap: 4px; }
.media-name {
  font-size: 0.875rem; font-weight: 500; color: var(--color-text);
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; word-break: break-word;
}
.media-sub { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 0.75rem; color: var(--color-muted); }
.media-cat { padding: 2px 8px; border-radius: 999px; background: var(--color-border); color: var(--color-text-secondary); white-space: nowrap; max-width: 70%; overflow: hidden; text-overflow: ellipsis; }
.media-actions { display: flex; align-items: center; gap: 4px; padding: 0 8px 10px; }
.media-actions .btn, .media-actions .btn-text-danger { padding: 4px 10px; }

.media-preview-item { display: block; max-width: 90vw; max-height: 70vh; margin: 0 auto; border-radius: 8px; }

/* Media category manager */
.cat-manage-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 0; border-bottom: 1px solid var(--color-border); }
.cat-manage-row:last-child { border-bottom: none; }
.cat-manage-name { font-size: 0.875rem; color: var(--color-text); word-break: break-word; }
.cat-manage-actions { display: flex; align-items: center; gap: 4px; flex-shrink: 0; }

@media (max-width: 768px) {
  #media-header { flex-wrap: wrap; }
  #media-header .flex-1 { order: -1; width: 100%; }
  .media-grid { gap: 12px; }
}
@media (max-width: 480px) {
  .media-grid { grid-template-columns: repeat(2, 1fr); gap: 8px; }
  .media-actions { flex-wrap: wrap; }
}
