:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --surface: #fff;
  --surface-2: #eef2f5;
  --text: #18212b;
  --muted: #63707d;
  --line: #d9e0e6;
  --accent: #176b5b;
  --accent-hover: #105448;
  --danger: #b3261e;
  --danger-hover: #8f1f19;
  --shadow: 0 10px 30px rgb(22 35 48 / 8%);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #11171d;
  --surface: #192129;
  --surface-2: #222d36;
  --text: #edf3f7;
  --muted: #aebac4;
  --line: #34424d;
  --accent: #248b77;
  --accent-hover: #2f9f89;
  --danger: #bd3c34;
  --danger-hover: #d04a42;
  --shadow: 0 10px 30px rgb(0 0 0 / 25%);
}

* { box-sizing: border-box; }
html { min-width: 320px; background: var(--bg); }
body { margin: 0; color: var(--text); background: var(--bg); line-height: 1.45; }
body.resizing-columns { cursor: col-resize; user-select: none; }
button, input, select, textarea { min-width: 0; max-width: 100%; font: inherit; color: var(--text); }
button, a, input, select, textarea { -webkit-tap-highlight-color: transparent; }
a { color: var(--accent); }
:focus { outline: none; }
:focus-visible { outline: none; }
input:focus-visible, select:focus-visible, textarea:focus-visible { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.button:focus-visible, .tabs button:focus-visible { border-color: var(--accent); box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--accent) 55%, transparent); }
a:focus-visible { text-decoration: underline 2px; text-underline-offset: 4px; }
[hidden] { display: none !important; }

.shell { width: min(100% - 24px, 1380px); margin-inline: auto; }
.topbar { position: sticky; top: 0; z-index: 10; background: color-mix(in srgb, var(--surface) 92%, transparent); border-bottom: 1px solid var(--line); backdrop-filter: blur(12px); }
.topbar-inner { min-height: 64px; display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding-block: 8px; }
.brand { min-width: 0; font-weight: 750; letter-spacing: -.02em; margin-right: auto; text-decoration: none; }
.user-name { display: none; color: var(--muted); }
.main { padding-block: 18px 48px; }
.grid { display: grid; gap: 18px; }
.card { min-width: 0; padding: 15px; background: var(--surface); border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow); }
h1, h2, h3 { margin: 0 0 14px; color: var(--text); line-height: 1.15; letter-spacing: -.02em; }
h1 { font-size: clamp(1.35rem, 3vw, 1.8rem); }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
p { color: var(--text); }

.form-grid { display: grid; grid-template-columns: minmax(0, 1fr); gap: 13px; }
.field { display: grid; min-width: 0; max-width: 100%; align-content: start; gap: 6px; }
.field label, .label { color: var(--text); font-size: .9rem; font-weight: 650; }
.field small { color: var(--muted); }
input, select, textarea { width: 100%; min-height: 46px; padding: 10px 12px; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; }
.field > input:not([type="checkbox"]), .field > select { height: 46px; min-height: 46px; max-height: 46px; }
input[type="date"] { display: block; min-width: 0; max-width: 100%; inline-size: 100%; -webkit-appearance: none; appearance: none; }
input[type="date"]::-webkit-date-and-time-value { min-width: 0; text-align: left; }
input[type="time"] { display: block; min-width: 0; max-width: 100%; inline-size: 100%; overflow: hidden; -webkit-appearance: none; appearance: none; }
input[type="time"]::-webkit-date-and-time-value { min-width: 0; text-align: left; }
textarea { min-height: 92px; max-height: 360px; overflow-y: auto; resize: none; white-space: pre-wrap; }
input:hover, select:hover, textarea:hover { border-color: var(--muted); }

.actions { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-top: 4px; }
.button { display: inline-flex; min-height: 44px; align-items: center; justify-content: center; padding: 9px 15px; color: #fff; font-weight: 700; text-decoration: none; cursor: pointer; background: var(--accent); border: 1px solid transparent; border-radius: 10px; }
.button:hover { background: var(--accent-hover); }
.button:active:not(:disabled) { transform: translateY(1px); }
.button:disabled { opacity: .58; cursor: not-allowed; }
.button.secondary { color: var(--text); background: var(--surface-2); border-color: var(--line); }
.button.secondary:hover { background: color-mix(in srgb, var(--surface-2) 75%, var(--line)); }
.button.ghost { color: var(--text); background: transparent; border-color: transparent; }
.button.ghost:hover { background: var(--surface-2); }
.button.danger { color: #fff; background: var(--danger); }
.button.danger:hover { background: var(--danger-hover); }
.button.small { min-height: 38px; padding: 6px 10px; font-size: .88rem; }

.toast { position: fixed; right: 12px; bottom: 12px; left: 12px; z-index: 30; max-width: 620px; margin: auto; padding: 13px 16px; color: #fff; background: #176b5b; border-radius: 12px; box-shadow: var(--shadow); }
.toast[data-kind="error"] { background: var(--danger); }

.history-header { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px 18px; margin-bottom: 14px; }
.history-header h2 { margin-bottom: 3px; }
.history-subtitle, .section-heading p { margin: 0; color: var(--muted); font-size: .9rem; }
.history-filter { flex: 0 0 auto; padding-inline: 4px; color: var(--text); font-weight: 650; }
.records-head { display: none; }
.column-resizer { display: none; }
.records-list { display: grid; gap: 10px; }
.record-row { position: relative; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); min-width: 0; align-items: start; gap: 9px 12px; padding: 12px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 12px; }
.record-cell { min-width: 0; color: var(--text); text-align: left; white-space: pre-wrap; overflow-wrap: anywhere; }
.record-cell::before, .record-actions::before { display: block; margin-bottom: 3px; color: var(--muted); font-size: .73rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; content: attr(data-label); }
.date-cell, .object-cell, .description-cell, .record-details, .record-actions { grid-column: 1 / -1; }
.description-cell { max-height: 11rem; padding-block: 8px; overflow: auto; border-block: 1px solid var(--line); }
.record-details { display: grid; justify-items: start; gap: 2px; color: var(--muted); font-size: .84rem; line-height: 1.3; }
.record-author { color: var(--text); font-size: .9rem; font-weight: 700; }
.record-editor, .record-updated { color: var(--muted); overflow-wrap: anywhere; }
.sync-status { width: fit-content; max-width: 100%; margin: 5px 0 0; padding: 3px 7px; color: var(--text); font-size: .73rem; font-weight: 700; line-height: 1.25; overflow-wrap: anywhere; background: var(--surface); border: 1px solid var(--line); border-radius: 999px; }
.status-synced { color: var(--accent); }
.status-failed { color: var(--danger); }
.record-actions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; min-width: 0; text-align: left; padding-top: 7px; border-top: 1px solid var(--line); }
.record-actions::before { grid-column: 1 / -1; }
.record-actions .button { width: 100%; min-height: 44px; }
.empty { padding: 24px; color: var(--muted); text-align: center; }

.login-layout { display: grid; min-height: 100svh; padding: 20px 12px; place-items: center; }
.login-card { width: min(100%, 420px); }
.login-card #login-form > .button { grid-column: 1 / -1; width: min(100%, 220px); margin-top: 8px; justify-self: center; }
.login-card > .actions { justify-content: center; }
.tabs { display: flex; gap: 6px; padding-bottom: 4px; margin-bottom: 16px; overflow-x: auto; }
.tabs button[aria-selected="true"] { color: #fff; background: var(--accent); }
.table-scroll { overflow: auto; border: 1px solid var(--line); border-radius: 12px; }
table { width: 100%; min-width: 760px; font-size: .9rem; border-collapse: collapse; }
th, td { padding: 10px 12px; color: var(--text); text-align: left; vertical-align: top; overflow-wrap: anywhere; border-bottom: 1px solid var(--line); }
th { position: sticky; top: 0; background: var(--surface-2); }
.table-actions { display: flex; flex-wrap: wrap; gap: 7px; }
.admin-layout { display: grid; gap: 16px; }
.admin-form { max-width: 680px; margin-bottom: 18px; }
.checkbox { display: flex; min-height: 44px; align-items: center; gap: 9px; color: var(--text); }
.checkbox input { width: 20px; min-height: 20px; accent-color: var(--accent); }
code { white-space: pre-wrap; overflow-wrap: anywhere; }

.section-heading { margin-bottom: 16px; }
.section-heading h2 { margin-bottom: 4px; }
.audit-list { display: grid; gap: 12px; }
.audit-card { padding: 14px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 12px; }
.audit-card h3 { margin-bottom: 10px; }
.audit-meta { margin: 0 0 5px; color: var(--muted); font-size: .82rem; }
.audit-changes { display: grid; gap: 7px; margin: 0; }
.audit-changes > div { display: grid; gap: 2px; padding-top: 7px; border-top: 1px solid var(--line); }
.audit-changes dt { color: var(--muted); font-size: .78rem; font-weight: 700; text-transform: uppercase; letter-spacing: .03em; }
.audit-changes dd { margin: 0; color: var(--text); white-space: pre-wrap; overflow-wrap: anywhere; }

.confirm-dialog { width: min(100% - 24px, 440px); padding: 20px; color: var(--text); background: var(--surface); border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow); }
.confirm-dialog::backdrop { background: rgb(0 0 0 / 55%); }
.confirm-dialog h2 { margin-bottom: 8px; }
.confirm-dialog p { margin: 0 0 18px; color: var(--muted); }
.confirm-dialog .actions { justify-content: flex-end; }

@media (min-width: 600px) {
  .shell { width: min(100% - 40px, 1380px); }
  .user-name { display: inline; }
  .card { padding: 18px; }
  .form-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .field-wide { grid-column: 1 / -1; }
  .audit-changes > div { grid-template-columns: 140px minmax(0, 1fr); gap: 12px; }
}

@media (min-width: 900px) {
  .history-header { flex-wrap: nowrap; }
  .records-head, .record-row { grid-template-columns: var(--history-columns, 72px minmax(96px, .9fr) 48px minmax(145px, 2fr) 82px minmax(165px, 1.3fr) 86px); column-gap: 10px; }
  .records-head { display: grid; padding: 0 11px 7px; color: var(--muted); font-size: .7rem; font-weight: 750; line-height: 1.25; text-transform: uppercase; letter-spacing: .025em; }
  .records-head > span { position: relative; min-width: 0; padding-inline: 5px; text-align: center; overflow-wrap: normal; }
  .column-resizer { position: absolute; top: -4px; right: -6px; bottom: -5px; z-index: 2; display: block; width: 12px; min-width: 12px; min-height: 28px; padding: 0; touch-action: none; cursor: col-resize; background: transparent; border: 0; border-radius: 4px; }
  .column-resizer::after { position: absolute; top: 4px; right: 5px; bottom: 4px; width: 1px; content: ""; background: var(--line); }
  .column-resizer:hover::after, .column-resizer:focus-visible::after, body.resizing-columns .column-resizer::after { width: 2px; background: var(--accent); }
  .column-resizer:focus-visible { box-shadow: none; }
  .record-row { align-items: center; padding: 10px; font-size: .88rem; line-height: 1.35; }
  .record-cell { align-self: center; text-align: center; }
  .date-cell, .object-cell, .description-cell, .record-details, .record-actions { grid-column: auto; }
  .record-cell::before, .record-actions::before { display: none; }
  .description-cell { max-height: 8.5rem; padding-block: 0; border-block: 0; }
  .record-details { justify-items: center; gap: 2px; font-size: .78rem; line-height: 1.25; }
  .record-author { font-size: .84rem; }
  .sync-status { margin: 4px auto 0; padding: 2px 6px; font-size: .69rem; }
  .hours-cell, .employees-cell { text-align: center; }
  .record-actions { display: grid; grid-template-columns: minmax(0, 1fr); align-self: center; align-content: center; gap: 6px; text-align: center; padding-top: 0; border-top: 0; }
  .record-actions .button { min-height: 34px; padding: 5px 7px; font-size: .78rem; }
}

@media (min-width: 1360px) {
  .grid { grid-template-columns: minmax(300px, 420px) minmax(0, 1fr); align-items: start; }
  .form-card { position: sticky; top: 82px; }
}

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