/* Concept 03: local presentation layer for staff, hours and general administration.
 * #app receives admin-ui + admin-{route} only on those three routes.
 * Private palette tokens avoid recoloring unrelated settings panels. Status
 * colors (--ok/--warn/--crit) remain inherited from the original stylesheet.
 * No external assets, fonts or changes to the application's route behavior.
 */
.admin-ui {
  --admin-bg: #f2f1ef;
  --admin-surface: #faf9f7;
  --admin-surface-2: #eae8e6;
  --admin-surface-3: #e3e0e4;
  --admin-ink: #202020;
  --admin-ink-2: #55535a;
  --admin-ink-3: #68656d;
  --admin-line: #d7d4d8;
  --admin-line-2: #bcb8c2;
  --admin-accent: #544094;
  --admin-accent-2: #6b54ac;
  --admin-accent-soft: #e6dff5;
  --admin-on-accent: #fff;
  --admin-font: "Helvetica Neue", Helvetica, Arial, sans-serif;
  min-height: 100vh;
  background: var(--admin-bg);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .admin-ui {
    --admin-bg: #0d0e10;
    --admin-surface: #161719;
    --admin-surface-2: #1d1e21;
    --admin-surface-3: #27272c;
    --admin-ink: #f3f1f0;
    --admin-ink-2: #c1bdc7;
    --admin-ink-3: #aaa8af;
    --admin-line: #323236;
    --admin-line-2: #56515e;
    --admin-accent: #d4c5fb;
    --admin-accent-2: #e6d7ff;
    --admin-accent-soft: #302b43;
    --admin-on-accent: #15111f;
  }
}

:root[data-theme="dark"] .admin-ui {
  --admin-bg: #0d0e10;
  --admin-surface: #161719;
  --admin-surface-2: #1d1e21;
  --admin-surface-3: #27272c;
  --admin-ink: #f3f1f0;
  --admin-ink-2: #c1bdc7;
  --admin-ink-3: #aaa8af;
  --admin-line: #323236;
  --admin-line-2: #56515e;
  --admin-accent: #d4c5fb;
  --admin-accent-2: #e6d7ff;
  --admin-accent-soft: #302b43;
  --admin-on-accent: #15111f;
}

/* Token mapping stops at these explicit regions. Other settings panels keep
 * the original fonts, colors, dimensions, inputs and actions. */
.admin-ui :is(.rail, .topbar, .mobbar),
.admin-ui:is(.admin-staff, .admin-hours) .canvas,
.admin-ui.admin-settings :is(.admin-organization, .admin-backups) {
  --bg: var(--admin-bg);
  --surface: var(--admin-surface);
  --surface-2: var(--admin-surface-2);
  --surface-3: var(--admin-surface-3);
  --ink: var(--admin-ink);
  --ink-2: var(--admin-ink-2);
  --ink-3: var(--admin-ink-3);
  --line: var(--admin-line);
  --line-2: var(--admin-line-2);
  --accent: var(--admin-accent);
  --accent-2: var(--admin-accent-2);
  --accent-soft: var(--admin-accent-soft);
  --on-accent: var(--admin-on-accent);
  --shadow: none;
  --r: 18px;
  --r-s: 10px;
  --sans: var(--admin-font);
  --serif: var(--admin-font);
  font-family: var(--sans);
  color: var(--ink);
}

.admin-ui .shell { grid-template-columns: 250px minmax(0, 1fr); }
.admin-ui .rail { background: var(--bg); }
.admin-ui .brand { padding: 23px 21px; }
.admin-ui .brand b {
  font: 400 32px/1.1 var(--sans);
  letter-spacing: -.06em;
  overflow-wrap: anywhere;
}
.admin-ui .brand span { display: block; margin-top: 9px; overflow-wrap: anywhere; }
.admin-ui .nav { padding: 10px 15px; }
.admin-ui .navitem { border-radius: 999px; font-size: 13px; min-height: 38px; padding: 9px 13px; }
.admin-ui .navitem[aria-current="true"] { color: var(--ink); font-weight: 500; }
.admin-ui .railfoot { padding: 16px; overflow-wrap: anywhere; }
.admin-ui .topbar { padding: 24px 30px; align-items: flex-start; background: var(--bg); }
.admin-ui .topbar > div { min-width: 0; }
.admin-ui .topbar h1 { font-size: clamp(30px, 3.4vw, 46px); font-weight: 300; letter-spacing: -.045em; line-height: 1.12; overflow-wrap: anywhere; }
.admin-ui .topbar .sub { margin-top: 12px; font-size: 13px; max-width: 640px; }
.admin-ui .topbar .chip { max-width: 100%; white-space: normal; overflow-wrap: anywhere; }
.admin-ui .canvas { padding: 26px 30px 56px; gap: 22px; }

.admin-ui:is(.admin-staff, .admin-hours) .panel,
.admin-ui.admin-settings .panel:is(.admin-organization, .admin-backups) { box-shadow: none; }
.admin-ui:is(.admin-staff, .admin-hours) .panel > header,
.admin-ui.admin-settings :is(.admin-organization, .admin-backups) > header { padding: 20px 23px; }
.admin-ui:is(.admin-staff, .admin-hours) .panel > header h2,
.admin-ui.admin-settings :is(.admin-organization, .admin-backups) > header h2 { font-weight: 400; font-size: 20px; letter-spacing: -.025em; }
.admin-ui:is(.admin-staff, .admin-hours) .panel .body:not(.tight),
.admin-ui.admin-settings :is(.admin-organization, .admin-backups) .body:not(.tight) { padding: 23px; }

.admin-ui :is(.rail, .topbar, .mobbar) .btn,
.admin-ui:is(.admin-staff, .admin-hours) .canvas .btn,
.admin-ui.admin-settings :is(.admin-organization, .admin-backups) .btn {
  border-radius: 999px;
  min-height: 38px;
  padding: 8px 15px;
  font-weight: 500;
}
.admin-ui .rail .btn.sm,
.admin-ui:is(.admin-staff, .admin-hours) .canvas .btn.sm,
.admin-ui.admin-settings :is(.admin-organization, .admin-backups) .btn.sm { min-height: 34px; padding: 6px 12px; }
.admin-ui:is(.admin-staff, .admin-hours) .canvas .btn.primary,
.admin-ui.admin-settings :is(.admin-organization, .admin-backups) .btn.primary {
  background: linear-gradient(110deg, #8290ff, #dc8ce9 65%, #f3a7c0);
  border-color: transparent;
  color: #171023;
}
.admin-ui:is(.admin-staff, .admin-hours) .canvas .btn.primary:hover:not(:disabled),
.admin-ui.admin-settings :is(.admin-organization, .admin-backups) .btn.primary:hover:not(:disabled) { filter: brightness(1.07); }

.admin-ui:is(.admin-staff, .admin-hours) .field,
.admin-ui.admin-settings :is(.admin-organization, .admin-backups) .field { min-width: 0; }
.admin-ui:is(.admin-staff, .admin-hours) .field label,
.admin-ui.admin-settings :is(.admin-organization, .admin-backups) .field label { font-size: 12px; text-transform: none; letter-spacing: 0; font-weight: 500; color: var(--ink-2); }
.admin-ui:is(.admin-staff, .admin-hours) .field :is(input, select, textarea),
.admin-ui.admin-settings :is(.admin-organization, .admin-backups) .field :is(input, select, textarea) {
  min-width: 0;
  min-height: 44px;
  max-width: 100%;
  padding: 11px 14px;
  border-radius: 12px;
  background: var(--surface-2);
}
.admin-ui.admin-settings .admin-organization input[readonly] { background: var(--surface); border-style: dashed; }
.admin-ui :is(.rail, .topbar, .mobbar) .chip,
.admin-ui:is(.admin-staff, .admin-hours) .canvas .chip,
.admin-ui.admin-settings :is(.admin-organization, .admin-backups) .chip { border-radius: 999px; font-weight: 400; padding: 4px 9px; }
.admin-ui:is(.admin-staff, .admin-hours) th { font-weight: 500; letter-spacing: .04em; font-size: 10.5px; }
.admin-ui:is(.admin-staff, .admin-hours) :is(td, th) { padding: 14px 17px; }
.admin-ui:is(.admin-staff, .admin-hours) .note,
.admin-ui.admin-settings :is(.admin-organization, .admin-backups) .note { border-radius: 12px; line-height: 1.6; }
.admin-ui :is(.rail, .topbar, .mobbar) :focus-visible,
.admin-ui:is(.admin-staff, .admin-hours) .canvas :focus-visible,
.admin-ui.admin-settings :is(.admin-organization, .admin-backups) :focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }

/* #overlay is a sibling, so it cannot inherit private tokens from #app.
 * Keep its existing palette and status colors, and adapt geometry only for
 * staff/time dialogs. Settings dialogs are outside this visual change. */
.admin-ui:is(.admin-staff, .admin-hours) ~ #overlay .modal { border-radius: 20px; box-shadow: none; }
.admin-ui:is(.admin-staff, .admin-hours) ~ #overlay .modal > header h3 { font: 400 20px/1.3 "Helvetica Neue", Helvetica, Arial, sans-serif; letter-spacing: -.025em; }
.admin-ui:is(.admin-staff, .admin-hours) ~ #overlay .modal .btn { border-radius: 999px; min-height: 38px; }
.admin-ui:is(.admin-staff, .admin-hours) ~ #overlay .modal .field :is(input, select, textarea) { min-width: 0; min-height: 44px; border-radius: 12px; }
.admin-ui:is(.admin-staff, .admin-hours) ~ #overlay .modal :focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }

/* Between the drawer breakpoint and a full desktop the wider rail, canvas and
 * cell padding above pushed the last column of the staff and hours tables
 * (Отключить / Выйти везде) out of their frame: at a 1024px window the staff
 * table needed 813px in a 712px frame, at 900px 729px in 646px. Here the rail
 * and paddings return to the original geometry, the staff row actions may
 * wrap onto a second line and long hours headers («Премия за перерывы») may
 * wrap, so neither table needs a sideways scroll on a desktop window. */
@media (min-width: 861px) and (max-width: 1199px) {
  .admin-ui .shell { grid-template-columns: 212px minmax(0, 1fr); }
  .admin-ui .canvas { padding: 22px 20px 52px; }
  .admin-ui:is(.admin-staff, .admin-hours) :is(td, th) { padding: 12px 10px; }
  .admin-ui:is(.admin-staff, .admin-hours) th { white-space: normal; }
  /* The actions cell carries an inline nowrap from app.js. */
  .admin-ui.admin-staff .tw td:last-child { white-space: normal !important; }
  .admin-ui.admin-staff .tw td:last-child :is(.btn, a.btn) { margin: 2px 0; }
}

/* Match the existing drawer breakpoint and preserve its focus/visibility rules. */
@media (max-width: 860px) {
  .admin-ui .shell { grid-template-columns: minmax(0, 1fr); }
  .admin-ui .topbar { padding: 21px 16px; }
  .admin-ui .canvas { padding: 20px 16px 45px; }
  .admin-ui .topbar h1 { font-size: 32px; }
  .admin-ui .mobbar b { font-weight: 400; letter-spacing: -.035em; }
  .admin-ui:is(.admin-staff, .admin-hours) .panel > header,
  .admin-ui.admin-settings :is(.admin-organization, .admin-backups) > header { padding: 16px; }
  .admin-ui:is(.admin-staff, .admin-hours) .panel .body:not(.tight),
  .admin-ui.admin-settings :is(.admin-organization, .admin-backups) .body:not(.tight) { padding: 16px; }
}

@media (hover: none), (max-width: 860px) {
  .admin-ui .rail :is(.btn, .btn.sm, .navitem),
  .admin-ui:is(.admin-staff, .admin-hours) .canvas :is(.btn, .btn.sm, .table-row-action),
  .admin-ui.admin-settings :is(.admin-organization, .admin-backups) :is(.btn, .btn.sm),
  .admin-ui:is(.admin-staff, .admin-hours) ~ #overlay .modal .btn { min-height: 44px; }
  .admin-ui:is(.admin-staff, .admin-hours) .field :is(input, select, textarea),
  .admin-ui.admin-settings :is(.admin-organization, .admin-backups) .field :is(input, select, textarea),
  .admin-ui:is(.admin-staff, .admin-hours) ~ #overlay .modal .field :is(input, select, textarea) { font-size: 16px; }
}

/* Shared appearance for the other existing screens. Administrative rules above
 * remain unchanged. This block changes only the shell's colors, local fonts,
 * button corners and focus ring; the original 212px rail, header dimensions,
 * 52px mobile bar and 860px drawer breakpoint still come from styles.css.
 * Private tokens on #app do not recolor or restyle the screen contents. */
#app.shell-ui:not(.admin-ui) {
  --shell-bg: #f2f1ef;
  --shell-surface: #faf9f7;
  --shell-surface-2: #eae8e6;
  --shell-surface-3: #e3e0e4;
  --shell-ink: #202020;
  --shell-ink-2: #55535a;
  --shell-ink-3: #68656d;
  --shell-line: #d7d4d8;
  --shell-line-2: #bcb8c2;
  --shell-accent: #544094;
  --shell-accent-2: #6b54ac;
  --shell-accent-soft: #e6dff5;
  --shell-on-accent: #fff;
  background: var(--shell-bg);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) #app.shell-ui:not(.admin-ui) {
    --shell-bg: #0d0e10;
    --shell-surface: #161719;
    --shell-surface-2: #1d1e21;
    --shell-surface-3: #27272c;
    --shell-ink: #f3f1f0;
    --shell-ink-2: #c1bdc7;
    --shell-ink-3: #aaa8af;
    --shell-line: #323236;
    --shell-line-2: #56515e;
    --shell-accent: #d4c5fb;
    --shell-accent-2: #e6d7ff;
    --shell-accent-soft: #302b43;
    --shell-on-accent: #15111f;
  }
}

:root[data-theme="dark"] #app.shell-ui:not(.admin-ui) {
  --shell-bg: #0d0e10;
  --shell-surface: #161719;
  --shell-surface-2: #1d1e21;
  --shell-surface-3: #27272c;
  --shell-ink: #f3f1f0;
  --shell-ink-2: #c1bdc7;
  --shell-ink-3: #aaa8af;
  --shell-line: #323236;
  --shell-line-2: #56515e;
  --shell-accent: #d4c5fb;
  --shell-accent-2: #e6d7ff;
  --shell-accent-soft: #302b43;
  --shell-on-accent: #15111f;
}

/* Map the original tokens only at the three shell regions. In particular,
 * neither .main nor .canvas inherits these overrides; status colors, panels,
 * tables, fields, dialogs and their handlers retain the existing behavior. */
#app.shell-ui:not(.admin-ui) > .shell > .rail,
#app.shell-ui:not(.admin-ui) > .shell > .main > :is(.topbar, .mobbar) {
  --bg: var(--shell-bg);
  --surface: var(--shell-surface);
  --surface-2: var(--shell-surface-2);
  --surface-3: var(--shell-surface-3);
  --ink: var(--shell-ink);
  --ink-2: var(--shell-ink-2);
  --ink-3: var(--shell-ink-3);
  --line: var(--shell-line);
  --line-2: var(--shell-line-2);
  --accent: var(--shell-accent);
  --accent-2: var(--shell-accent-2);
  --accent-soft: var(--shell-accent-soft);
  --on-accent: var(--shell-on-accent);
  color: var(--ink);
}

/* Keep the existing topbar fonts: their metrics determine when the date/user
 * chips wrap, and therefore where the untouched screen contents begin. */
#app.shell-ui:not(.admin-ui) > .shell > .rail,
#app.shell-ui:not(.admin-ui) > .shell > .main > .mobbar {
  --sans: "Helvetica Neue", Helvetica, Arial, sans-serif;
  --serif: var(--sans);
  font-family: var(--sans);
}

#app.shell-ui:not(.admin-ui) > .shell > .rail,
#app.shell-ui:not(.admin-ui) > .shell > .main > .topbar { background: var(--bg); }

#app.shell-ui:not(.admin-ui) > .shell > .rail :is(.navitem, .btn),
#app.shell-ui:not(.admin-ui) > .shell > .main > :is(.topbar, .mobbar) .btn { border-radius: 999px; }

#app.shell-ui:not(.admin-ui) > .shell > .rail :focus-visible,
#app.shell-ui:not(.admin-ui) > .shell > .main > :is(.topbar, .mobbar) :focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }

/* The user chip may contain a long name and role. Let it wrap inside the
 * existing header; keep the date, rail and heading dimensions unchanged. */
#app.shell-ui > .shell > .main > .topbar > .chip.acc {
  min-width: 0;
  max-width: 100%;
  white-space: normal;
  overflow-wrap: anywhere;
}

/* Time summaries use dedicated wrappers rather than the generic .row .t.
 * Separate labels from values without changing their text or actions. */
#app.admin-hours > .shell > .main > .canvas .row > :is(.mine, .sheet) {
  display: flex;
  flex: 1;
  flex-direction: column;
  min-width: 0;
  gap: 4px;
  overflow-wrap: anywhere;
}
