:root {
  --bg: #f4f6f5;
  --surface: #ffffff;
  --surface-2: #f8faf9;
  --ink: #17201d;
  --muted: #68736f;
  --line: #dce3e0;
  --nav: #18211f;
  --nav-muted: #9eaaa6;
  --green: #167856;
  --green-soft: #e5f3ed;
  --coral: #ca513e;
  --amber: #a36414;
  --amber-soft: #fff2dc;
  --blue: #315c91;
  --shadow: 0 14px 40px rgba(23, 32, 29, .12);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--bg);
  font-synthesis: none;
}

* { box-sizing: border-box; }
body { margin: 0; min-width: 320px; min-height: 100vh; background: var(--bg); }
button, input, select, textarea { font: inherit; letter-spacing: 0; }
button { color: inherit; }
.hidden { display: none !important; }
.eyebrow { color: var(--green); font-size: 11px; font-weight: 750; text-transform: uppercase; letter-spacing: .08em; }

.login-screen { min-height: 100vh; display: grid; grid-template-columns: 1fr 460px; background: var(--nav); color: white; }
.login-brand { padding: 42px 5vw; display: flex; align-items: flex-start; gap: 12px; position: relative; overflow: hidden; }
.login-brand::after { content: "ПРАВО\A В ПОРЯДКЕ"; white-space: pre; position: absolute; left: 5vw; bottom: 7vh; font-size: clamp(58px, 9vw, 138px); line-height: .84; font-weight: 780; color: #dbe9e2; }
.brand-mark { width: 38px; height: 38px; display: grid; place-items: center; background: #d8f078; color: #18211f; font-size: 13px; font-weight: 850; border-radius: 4px; flex: 0 0 auto; }
.login-brand strong, .sidebar-brand strong { display: block; font-size: 16px; }
.login-brand span, .sidebar-brand span { display: block; margin-top: 2px; font-size: 10px; color: var(--nav-muted); text-transform: uppercase; letter-spacing: .08em; }
.login-panel { background: var(--surface); color: var(--ink); padding: clamp(40px, 8vh, 100px) 58px; display: flex; flex-direction: column; justify-content: center; box-shadow: -25px 0 70px rgba(0,0,0,.14); }
.login-panel h1 { margin: 10px 0 12px; font-size: 32px; line-height: 1.05; letter-spacing: 0; }
.login-panel > p { margin: 0 0 42px; color: var(--muted); line-height: 1.55; font-size: 14px; }
label { display: grid; gap: 7px; margin-bottom: 18px; color: #4f5b57; font-size: 12px; font-weight: 650; }
input, select, textarea { width: 100%; border: 1px solid var(--line); border-radius: 5px; background: white; color: var(--ink); padding: 11px 12px; outline: none; transition: border-color .15s, box-shadow .15s; }
input:focus, select:focus, textarea:focus { border-color: var(--green); box-shadow: 0 0 0 3px rgba(22,120,86,.1); }
textarea { resize: vertical; }
.primary, .button { min-height: 38px; padding: 0 14px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; border-radius: 5px; border: 1px solid transparent; font-weight: 700; font-size: 13px; cursor: pointer; }
.primary { background: var(--green); color: white; }
.primary:hover { background: #126749; }
.primary svg, .button svg { width: 16px; height: 16px; }
.wide { width: 100%; min-height: 44px; margin-top: 4px; justify-content: space-between; }
.button { background: var(--surface); border-color: var(--line); }
.button:hover { background: var(--surface-2); }
.login-panel small { text-align: center; margin-top: 18px; color: #8a9490; }
.login-separator { position: relative; margin: 18px 0; border-top: 1px solid var(--line); text-align: center; }
.login-separator span { position: relative; top: -9px; padding: 0 9px; background: var(--surface); color: var(--muted); font-size: 10px; }
.nextcloud-login { margin-top: 0; color: var(--ink); text-decoration: none; }
.form-error { color: var(--coral); min-height: 18px; margin-top: 10px; font-size: 12px; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 224px 1fr; grid-template-rows: 64px 1fr; }
.sidebar { position: fixed; z-index: 20; inset: 0 auto 0 0; width: 224px; background: var(--nav); color: white; display: flex; flex-direction: column; padding: 18px 12px 12px; }
.sidebar-brand { padding: 2px 8px 28px; display: flex; align-items: center; gap: 10px; }
.main-nav { display: grid; gap: 3px; }
.main-nav button { border: 0; background: transparent; color: var(--nav-muted); min-height: 42px; padding: 0 10px; border-radius: 5px; display: grid; grid-template-columns: 20px 1fr auto; align-items: center; gap: 10px; text-align: left; cursor: pointer; font-size: 13px; }
.main-nav button:hover { background: rgba(255,255,255,.06); color: white; }
.main-nav button.active { background: #293531; color: white; box-shadow: inset 3px 0 #d8f078; }
.main-nav svg { width: 17px; height: 17px; }
.main-nav b { min-width: 21px; height: 20px; padding: 0 6px; display: grid; place-items: center; background: rgba(255,255,255,.08); border-radius: 10px; font-size: 10px; }
.nav-section-label { margin: 28px 10px 8px; color: #66726e; font-size: 9px; font-weight: 800; text-transform: uppercase; letter-spacing: .12em; }
.secondary { margin-bottom: auto; }
.sidebar-footer { border-top: 1px solid rgba(255,255,255,.1); padding: 14px 6px 2px; display: grid; grid-template-columns: 32px 1fr 30px; align-items: center; gap: 9px; }
.avatar { width: 32px; height: 32px; display: grid; place-items: center; border-radius: 50%; background: #d8f078; color: var(--nav); font-size: 11px; font-weight: 850; }
.sidebar-footer strong { display: block; font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-footer span { display: block; margin-top: 2px; color: var(--nav-muted); font-size: 9px; }
.sidebar-footer button { border: 0; background: transparent; color: var(--nav-muted); cursor: pointer; padding: 6px; }
.sidebar-footer svg { width: 16px; }

.topbar { position: sticky; top: 0; z-index: 15; grid-column: 2; height: 64px; background: rgba(255,255,255,.96); border-bottom: 1px solid var(--line); display: grid; grid-template-columns: 1fr minmax(240px, 400px) auto auto; align-items: center; gap: 12px; padding: 0 24px; backdrop-filter: blur(8px); }
.breadcrumbs { display: flex; align-items: center; gap: 6px; min-width: 0; font-size: 12px; }
.breadcrumbs span { color: var(--muted); }
.breadcrumbs strong { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.breadcrumbs svg { width: 13px; color: #a1aaa7; }
.global-search { margin: 0; display: grid; grid-template-columns: 18px 1fr auto; align-items: center; gap: 7px; border: 1px solid var(--line); border-radius: 5px; padding: 0 9px; color: var(--muted); }
.global-search input { border: 0; box-shadow: none; padding: 9px 0; background: transparent; }
.global-search svg { width: 16px; }
kbd { border: 1px solid var(--line); border-radius: 3px; padding: 2px 5px; background: var(--surface-2); font-size: 9px; color: #7b8581; }
.icon-button { width: 36px; height: 36px; border: 1px solid var(--line); border-radius: 5px; background: var(--surface); display: grid; place-items: center; cursor: pointer; position: relative; }
.icon-button:hover { background: var(--surface-2); }
.icon-button svg { width: 17px; height: 17px; }
.icon-button.compact { width: 30px; height: 30px; flex: 0 0 auto; }
.icon-button.compact svg { width: 14px; height: 14px; }
.icon-button.compact:hover { color: var(--coral); }
.primary:disabled, .button:disabled { opacity: .55; cursor: wait; }
.notification-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--coral); position: absolute; top: 7px; right: 7px; border: 1px solid white; }
.mobile-menu { display: none; }

.workspace { grid-column: 2; padding: 26px 28px 56px; min-width: 0; }
.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 20px; margin-bottom: 24px; }
.page-head h1 { margin: 0; font-size: 25px; line-height: 1.2; letter-spacing: 0; }
.page-head p { margin: 6px 0 0; color: var(--muted); font-size: 13px; }
.page-actions { display: flex; gap: 8px; }
.metric-grid { display: grid; grid-template-columns: repeat(4, minmax(0,1fr)); border: 1px solid var(--line); border-radius: 6px; overflow: hidden; margin-bottom: 20px; background: var(--surface); }
.metric { min-height: 106px; padding: 20px; border-right: 1px solid var(--line); }
.metric:last-child { border: 0; }
.metric-top { display: flex; justify-content: space-between; color: var(--muted); font-size: 11px; font-weight: 650; }
.metric-top svg { width: 17px; }
.metric strong { display: block; margin-top: 12px; font-size: 29px; line-height: 1; }
.metric small { display: block; margin-top: 9px; color: var(--muted); font-size: 10px; }
.accent-coral { color: var(--coral); }
.accent-green { color: var(--green); }
.accent-amber { color: var(--amber); }
.dashboard-grid { display: grid; grid-template-columns: minmax(0,1.65fr) minmax(300px,.75fr); gap: 18px; }
.stack { display: grid; gap: 18px; align-content: start; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.panel-head { min-height: 54px; padding: 0 17px; display: flex; align-items: center; justify-content: space-between; gap: 12px; border-bottom: 1px solid var(--line); }
.panel-head h2 { margin: 0; font-size: 14px; }
.text-button { border: 0; background: transparent; color: var(--green); padding: 5px; font-size: 11px; font-weight: 750; cursor: pointer; }

.data-table { width: 100%; border-collapse: collapse; table-layout: fixed; }
.data-table th { padding: 10px 14px; background: var(--surface-2); border-bottom: 1px solid var(--line); color: var(--muted); text-align: left; font-size: 9px; text-transform: uppercase; letter-spacing: .06em; }
.data-table td { height: 59px; padding: 9px 14px; border-bottom: 1px solid #edf0ef; font-size: 12px; vertical-align: middle; }
.data-table tr:last-child td { border-bottom: 0; }
.data-table tbody tr { cursor: pointer; }
.data-table tbody tr:hover { background: #fafcfb; }
.actions-cell { width: 46px; text-align: right !important; }
.cell-main { display: block; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; font-weight: 650; }
.cell-sub { display: block; margin-top: 3px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; color: var(--muted); font-size: 10px; }
.case-number { color: var(--green); font-size: 10px; font-weight: 800; }
.badge { display: inline-flex; align-items: center; min-height: 23px; padding: 0 8px; border-radius: 4px; background: #eef1f0; color: #56605d; font-size: 10px; font-weight: 750; white-space: nowrap; }
.badge.new { background: #e7f0fa; color: var(--blue); }
.badge.in_progress { background: var(--green-soft); color: var(--green); }
.badge.review { background: var(--amber-soft); color: var(--amber); }
.badge.waiting { background: #f1ecf7; color: #745390; }
.badge.closed { background: #edf0ef; color: #69736f; }
.priority-dot { width: 7px; height: 7px; border-radius: 50%; display: inline-block; margin-right: 7px; background: #afb8b5; }
.priority-dot.high { background: var(--coral); }
.assignee { display: inline-flex; align-items: center; gap: 7px; }
.mini-avatar { width: 24px; height: 24px; display: grid; place-items: center; border-radius: 50%; background: #e2ece7; color: var(--green); font-size: 8px; font-weight: 850; }
.list { display: grid; }
.list-item { min-height: 62px; padding: 11px 15px; display: grid; grid-template-columns: 35px minmax(0,1fr) auto; align-items: center; gap: 10px; border-bottom: 1px solid #edf0ef; }
.list-item:last-child { border-bottom: 0; }
.list-icon { width: 32px; height: 32px; display: grid; place-items: center; border-radius: 5px; background: var(--surface-2); color: var(--green); }
.list-icon svg { width: 15px; }
.list-item strong { display: block; font-size: 11px; line-height: 1.35; }
.list-item span { display: block; margin-top: 3px; color: var(--muted); font-size: 9px; }
.list-item time { color: var(--muted); font-size: 10px; white-space: nowrap; }
.overdue { color: var(--coral) !important; }
.progress { height: 5px; background: #e7ebe9; border-radius: 3px; overflow: hidden; margin-top: 9px; }
.progress span { display: block; height: 100%; background: var(--green); }
.budget-row { padding: 16px; }
.budget-row > div { display: flex; justify-content: space-between; font-size: 11px; }
.budget-row strong { font-size: 13px; }

.toolbar { display: flex; align-items: center; gap: 8px; margin-bottom: 14px; }
.toolbar-search { width: min(360px,100%); position: relative; }
.toolbar-search svg { width: 15px; position: absolute; left: 11px; top: 11px; color: var(--muted); }
.toolbar-search input { padding-left: 34px; }
.filter-tabs { display: flex; gap: 4px; margin-left: 5px; }
.filter-tabs button { height: 36px; border: 1px solid var(--line); background: var(--surface); border-radius: 4px; padding: 0 11px; color: var(--muted); font-size: 10px; font-weight: 700; cursor: pointer; }
.filter-tabs button.active { background: var(--ink); border-color: var(--ink); color: white; }
.table-panel { overflow-x: auto; }
.table-panel .data-table { min-width: 850px; }
.empty { padding: 48px 20px; text-align: center; color: var(--muted); font-size: 12px; }

.case-detail-head { display: grid; grid-template-columns: 38px minmax(0,1fr) auto; gap: 12px; align-items: start; }
.case-detail-head h1 { font-size: 22px; }
.case-detail-head .icon-button { margin-top: 2px; }
.detail-grid { display: grid; grid-template-columns: minmax(0,1.7fr) minmax(280px,.7fr); gap: 18px; }
.detail-summary { padding: 18px; }
.detail-summary p { margin: 0; color: #46514d; font-size: 13px; line-height: 1.6; }
.field-grid { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); margin-top: 20px; border-top: 1px solid var(--line); border-left: 1px solid var(--line); }
.field { min-height: 72px; padding: 13px; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.field span { display: block; color: var(--muted); font-size: 9px; text-transform: uppercase; letter-spacing: .06em; }
.field strong { display: block; margin-top: 7px; font-size: 12px; }
.tabs { display: flex; gap: 18px; padding: 0 17px; border-bottom: 1px solid var(--line); overflow-x: auto; }
.tabs button { min-height: 42px; border: 0; border-bottom: 2px solid transparent; background: none; color: var(--muted); font-size: 11px; font-weight: 700; cursor: pointer; white-space: nowrap; }
.tabs button.active { color: var(--green); border-bottom-color: var(--green); }
.tab-content { min-height: 180px; }
.status-select { min-width: 150px; padding: 8px 10px; font-size: 11px; }

.client-grid { display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); gap: 12px; }
.client-card { padding: 17px; background: var(--surface); border: 1px solid var(--line); border-radius: 6px; }
.client-card header { display: flex; justify-content: space-between; gap: 10px; }
.client-card h3 { margin: 0; font-size: 13px; }
.client-card p { margin: 14px 0; color: var(--muted); font-size: 11px; line-height: 1.65; }
.client-card footer { display: flex; justify-content: space-between; padding-top: 11px; border-top: 1px solid var(--line); color: var(--muted); font-size: 10px; }
.card-actions, .row-actions { display: inline-flex; align-items: center; justify-content: flex-end; gap: 5px; }

.task-layout { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.task-row { min-height: 58px; padding: 10px 14px; display: grid; grid-template-columns: 22px minmax(0,1fr) auto auto; align-items: center; gap: 10px; border-bottom: 1px solid #edf0ef; }
.task-row:last-child { border: 0; }
.task-row input { width: 16px; height: 16px; accent-color: var(--green); }
.task-row strong { display: block; font-size: 11px; }
.task-row span { display: block; margin-top: 3px; color: var(--muted); font-size: 9px; }
.task-row.completed strong { color: var(--muted); text-decoration: line-through; }

.calendar-strip { display: grid; grid-template-columns: repeat(7,minmax(0,1fr)); background: var(--surface); border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.calendar-day { min-height: 420px; padding: 12px 8px; border-right: 1px solid var(--line); }
.calendar-day:last-child { border: 0; }
.calendar-day header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; color: var(--muted); font-size: 9px; text-transform: uppercase; }
.calendar-day header strong { width: 26px; height: 26px; display: grid; place-items: center; color: var(--ink); font-size: 11px; }
.calendar-day.today header strong { background: var(--green); color: white; border-radius: 50%; }
.event-card { margin-bottom: 7px; padding: 9px; border-left: 3px solid var(--green); border-radius: 3px; background: var(--green-soft); }
.event-card.hearing { border-color: var(--coral); background: #fbeae7; }
.event-card.deadline { border-color: var(--amber); background: var(--amber-soft); }
.event-card time { display: block; margin-bottom: 4px; color: var(--muted); font-size: 8px; }
.event-card strong { display: block; font-size: 9px; line-height: 1.4; }
.event-card span { display: block; margin-top: 4px; color: var(--muted); font-size: 8px; overflow: hidden; text-overflow: ellipsis; }
.event-card time { display: flex; align-items: center; justify-content: space-between; gap: 4px; }
.event-card .icon-button { border: 0; background: transparent; width: 22px; height: 22px; }

.document-row { display: grid; grid-template-columns: 34px minmax(0,1.7fr) minmax(120px,.7fr) 90px 90px 72px; align-items: center; gap: 10px; min-height: 62px; padding: 8px 15px; border-bottom: 1px solid var(--line); font-size: 11px; }
.document-row:last-child { border: 0; }
.document-icon { width: 30px; height: 34px; display: grid; place-items: center; background: #edf2f0; border-radius: 4px; color: var(--green); }
.document-icon svg { width: 16px; }
.integration-banner { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; padding: 13px 15px; border: 1px solid #cfded7; border-radius: 6px; background: var(--green-soft); }
.integration-banner > svg { width: 22px; color: var(--green); }
.integration-banner strong { display: block; font-size: 11px; }
.integration-banner span { display: block; margin-top: 3px; color: var(--muted); font-size: 9px; }
.integration-banner .badge { margin-left: auto; }

.report-grid, .settings-grid { display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); gap: 12px; }
.report-card, .setting-card { min-height: 150px; padding: 18px; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); }
.report-card svg, .setting-card svg { width: 21px; color: var(--green); }
.report-card h3, .setting-card h3 { margin: 28px 0 7px; font-size: 13px; }
.report-card p, .setting-card p { margin: 0; color: var(--muted); font-size: 10px; line-height: 1.5; }
.report-value { display: block; margin-top: 10px; font-size: 23px; }

.modal-backdrop { position: fixed; z-index: 50; inset: 0; display: grid; place-items: center; padding: 20px; background: rgba(12,18,16,.62); }
.modal { width: min(620px,100%); max-height: calc(100vh - 40px); overflow: auto; background: var(--surface); border-radius: 7px; box-shadow: var(--shadow); }
.modal > header { padding: 20px 22px 16px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: flex-start; }
.modal h2 { margin: 5px 0 0; font-size: 20px; }
.modal form { padding: 20px 22px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.modal footer { display: flex; justify-content: flex-end; gap: 8px; padding-top: 6px; }
.toast { position: fixed; z-index: 70; right: 22px; bottom: 22px; max-width: 350px; padding: 12px 15px; border-radius: 5px; background: var(--nav); color: white; box-shadow: var(--shadow); font-size: 11px; opacity: 0; transform: translateY(12px); pointer-events: none; transition: .2s; }
.toast.visible { opacity: 1; transform: translateY(0); }

@media (max-width: 1050px) {
  .metric-grid { grid-template-columns: repeat(2,1fr); }
  .metric:nth-child(2) { border-right: 0; }
  .metric:nth-child(-n+2) { border-bottom: 1px solid var(--line); }
  .dashboard-grid, .detail-grid { grid-template-columns: 1fr; }
  .client-grid, .report-grid, .settings-grid { grid-template-columns: repeat(2,1fr); }
  .global-search { display: none; }
  .topbar { grid-template-columns: 1fr auto auto; }
}

@media (max-width: 760px) {
  .login-screen { display: block; background: var(--surface); }
  .login-brand { min-height: 170px; }
  .login-brand::after { display: none; }
  .login-panel { padding: 38px 24px; box-shadow: none; }
  .app-shell { display: block; padding-top: 60px; }
  .sidebar { transform: translateX(-100%); transition: transform .2s; box-shadow: var(--shadow); }
  .sidebar.open { transform: translateX(0); }
  .topbar { position: fixed; left: 0; right: 0; height: 60px; grid-template-columns: auto 1fr auto auto; padding: 0 12px; }
  .mobile-menu { display: grid; }
  .topbar .primary span { display: none; }
  .topbar .primary { width: 36px; padding: 0; }
  .workspace { padding: 20px 14px 42px; }
  .page-head { align-items: center; }
  .page-head h1 { font-size: 21px; }
  .page-head p { display: none; }
  .page-actions .button span { display: none; }
  .metric { min-height: 95px; padding: 15px; }
  .metric strong { font-size: 24px; }
  .client-grid, .report-grid, .settings-grid, .task-layout { grid-template-columns: 1fr; }
  .toolbar { flex-wrap: wrap; }
  .toolbar-search { width: 100%; }
  .filter-tabs { margin: 0; overflow-x: auto; max-width: 100%; }
  .case-detail-head { grid-template-columns: 36px minmax(0,1fr); }
  .case-detail-head .page-actions { grid-column: 1 / 3; }
  .field-grid { grid-template-columns: 1fr; }
  .calendar-strip { overflow-x: auto; grid-template-columns: repeat(7,150px); }
  .calendar-day { min-height: 300px; }
  .document-row { grid-template-columns: 34px minmax(0,1fr) 72px; }
  .document-row > :nth-child(3), .document-row > :nth-child(4), .document-row > :nth-child(5) { display: none; }
  .form-row { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) { * { scroll-behavior: auto !important; transition: none !important; } }
