:root {
  color-scheme: light;
  --bg: #f5f6f3;
  --panel: #ffffff;
  --ink: #18211f;
  --muted: #69746f;
  --line: #d9ded8;
  --line-strong: #b8c0bb;
  --accent: #176b5d;
  --accent-strong: #0f4f45;
  --accent-soft: #e3f0ed;
  --blue: #2e5f9f;
  --amber: #b7791f;
  --red: #b23939;
  --green: #1c7c55;
  --shadow: 0 18px 48px rgba(24, 33, 31, 0.08);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body,
#app {
  min-height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-size: 14px;
  letter-spacing: 0;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  border-radius: 7px;
  padding: 9px 12px;
  cursor: pointer;
  min-height: 36px;
}

button:hover {
  border-color: var(--line-strong);
  background: #fafbf9;
}

button.primary {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

button.primary:hover {
  border-color: var(--accent-strong);
  background: var(--accent-strong);
}

button.danger {
  border-color: #e8caca;
  color: var(--red);
}

button.compact {
  min-height: 30px;
  padding: 5px 8px;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  color: var(--ink);
  padding: 9px 10px;
  min-height: 36px;
}

textarea {
  min-height: 88px;
  resize: vertical;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

table {
  width: 100%;
  border-collapse: collapse;
  white-space: nowrap;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 9px 10px;
  text-align: left;
  vertical-align: middle;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #f9faf8;
  color: #53605b;
  font-size: 12px;
  font-weight: 700;
}

td.number,
th.number {
  text-align: right;
}

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    linear-gradient(115deg, rgba(23, 107, 93, 0.16), transparent 42%),
    linear-gradient(330deg, rgba(183, 121, 31, 0.12), transparent 34%),
    var(--bg);
}

.login-panel {
  width: min(430px, 100%);
  display: grid;
  gap: 22px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 28px;
  box-shadow: var(--shadow);
}

.login-panel h1 {
  margin: 3px 0 0;
  font-size: 29px;
  line-height: 1.08;
}

.eyebrow {
  margin: 0;
  color: var(--accent);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.12em;
}

.login-form,
.form-grid {
  display: grid;
  gap: 14px;
}

.error-message {
  min-height: 18px;
  margin: 0;
  color: var(--red);
  font-weight: 700;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 248px minmax(0, 1fr);
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 18px;
  border-right: 1px solid var(--line);
  background: #eef2ef;
  padding: 18px;
}

.brand {
  display: grid;
  gap: 3px;
}

.brand strong {
  font-size: 18px;
}

.brand span,
.user-line,
.muted {
  color: var(--muted);
}

.nav {
  display: grid;
  align-content: start;
  gap: 6px;
}

.nav button {
  width: 100%;
  text-align: left;
  border-color: transparent;
  background: transparent;
}

.nav button.active {
  background: #fff;
  border-color: var(--line);
  color: var(--accent-strong);
  font-weight: 800;
}

.sidebar-footer {
  display: grid;
  gap: 10px;
}

.content {
  min-width: 0;
  display: grid;
  align-content: start;
  gap: 18px;
  padding: 22px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.topbar h1 {
  margin: 0;
  font-size: 24px;
}

.toolbar {
  display: flex;
  align-items: end;
  flex-wrap: wrap;
  gap: 10px;
}

.toolbar label {
  min-width: 165px;
}

.section {
  display: grid;
  gap: 14px;
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.section-header h2 {
  margin: 0;
  font-size: 18px;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(160px, 1fr));
  gap: 10px;
}

.kpi {
  display: grid;
  gap: 8px;
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 8px;
  padding: 14px;
}

.kpi span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.kpi strong {
  font-size: 21px;
}

.panel {
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 8px;
  overflow: hidden;
}

.panel-body {
  padding: 14px;
}

.table-wrap {
  overflow: auto;
  max-height: 68vh;
}

.wide-table th:first-child,
.wide-table td:first-child {
  position: sticky;
  left: 0;
  z-index: 2;
  background: inherit;
}

.wide-table td:first-child {
  background: #fff;
}

.wide-table th:first-child {
  background: #f9faf8;
}

.matrix-wrap {
  max-height: 72vh;
}

.matrix-table {
  table-layout: fixed;
  min-width: 1410px;
  font-size: 12px;
}

.matrix-table th,
.matrix-table td {
  height: 27px;
  padding: 2px 3px;
  border: 1px solid #d7dcd4;
}

.matrix-table th {
  z-index: 3;
}

.matrix-table .matrix-employee {
  position: sticky;
  left: 0;
  z-index: 4;
  width: 200px;
  min-width: 200px;
  background: #eaf2df;
}

.matrix-table td.matrix-employee {
  z-index: 2;
}

.matrix-table .matrix-employee.alt {
  background: #dcecff;
}

.matrix-table .matrix-indicator {
  position: sticky;
  left: 200px;
  z-index: 4;
  width: 142px;
  min-width: 142px;
  background: #f8faf6;
}

.matrix-table td.matrix-indicator {
  z-index: 2;
  color: #1f2b27;
  font-weight: 600;
}

.matrix-employee strong,
.matrix-employee span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
}

.matrix-employee span {
  margin-top: 2px;
  color: var(--muted);
  font-size: 11px;
}

.matrix-day-header {
  width: 42px;
  min-width: 42px;
  text-align: center;
}

.matrix-day-header strong,
.matrix-day-header span {
  display: block;
  line-height: 1.1;
}

.matrix-day-header span {
  color: var(--muted);
  font-size: 10px;
}

.matrix-day-header.is-weekend,
.matrix-day-cell.is-weekend {
  background: #fff2d8;
}

.matrix-day-header.is-holiday,
.matrix-day-cell.is-holiday {
  background: #fde8e8;
}

.employee-start td {
  border-top: 2px solid #8aa08f;
}

.matrix-input,
.matrix-status {
  width: 100%;
  min-width: 0;
  min-height: 22px;
  height: 22px;
  border: 0;
  border-radius: 0;
  padding: 1px 2px;
  text-align: center;
  background: transparent;
  font-size: 10px;
  line-height: 1;
  appearance: textfield;
  -moz-appearance: textfield;
}

.matrix-input::-webkit-outer-spin-button,
.matrix-input::-webkit-inner-spin-button {
  margin: 0;
  appearance: none;
}

.matrix-input:focus,
.matrix-status:focus {
  outline: 2px solid var(--accent);
  background: #fff;
}

.matrix-value,
.attendance-badge {
  display: grid;
  min-height: 21px;
  place-items: center;
  text-align: center;
  font-size: 10px;
  font-weight: 700;
}

.attendance-badge,
.matrix-status {
  font-size: 12px;
  font-weight: 800;
}

.status-Я {
  background: #9edb87;
  color: #0d411d;
}

.status-Н {
  background: #78d8cf;
  color: #073f3b;
}

.status-В {
  background: #d9ded8;
  color: #29302d;
}

.status-Б {
  background: #f4b2b2;
  color: #751d1d;
}

.status-О {
  background: #ffc978;
  color: #623800;
}

.status-НЯ {
  background: #ffe66d;
  color: #594500;
}

.status-П {
  background: #d7b7ff;
  color: #4b1f75;
}

.status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border-radius: 999px;
  border: 1px solid var(--line);
  padding: 4px 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.status.ok {
  border-color: #b9decf;
  background: #edf8f3;
  color: var(--green);
}

.status.warn {
  border-color: #ead7ad;
  background: #fff6df;
  color: var(--amber);
}

.status.closed {
  border-color: #d8d4cc;
  background: #efeee9;
  color: #6b6259;
}

.filters {
  display: grid;
  grid-template-columns: repeat(5, minmax(130px, 1fr));
  gap: 10px;
}

.split {
  display: grid;
  grid-template-columns: 330px minmax(0, 1fr);
  gap: 14px;
  align-items: start;
}

.employee-list {
  display: grid;
  gap: 6px;
  max-height: 70vh;
  overflow: auto;
}

.employee-list button {
  display: grid;
  gap: 3px;
  text-align: left;
  background: #fff;
}

.employee-list button.active {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.employee-name {
  font-weight: 800;
}

.employee-meta {
  color: var(--muted);
  font-size: 12px;
}

.rates-row {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}

.country-switcher {
  display: inline-flex;
  border-radius: 7px;
  overflow: hidden;
  border: 1px solid var(--line);
  margin-bottom: 8px;
}

.country-switcher button {
  display: block;
  flex: 1;
  border: none;
  border-radius: 0;
  padding: 7px 16px;
  font-size: 13px;
  font-weight: 600;
  text-align: center;
  background: #fff;
  color: var(--muted);
  min-height: unset;
}

.country-switcher button:not(:last-child) {
  border-right: 1px solid var(--line);
}

.country-switcher button.cs-active {
  background: var(--accent);
  color: #fff;
}

.country-switcher button:hover:not(.cs-active) {
  background: var(--accent-soft);
  color: var(--accent);
}

.cell-input {
  width: 78px;
  min-height: 30px;
  padding: 5px 6px;
}

.status-select {
  width: 62px;
  min-height: 30px;
  padding: 5px 6px;
}

.comment-input {
  min-width: 170px;
}

.calendar-select,
.calendar-boolean,
.calendar-name,
.calendar-hours {
  min-height: 30px;
  padding: 5px 6px;
}

.calendar-select {
  min-width: 150px;
}

.calendar-boolean {
  min-width: 74px;
}

.calendar-name {
  min-width: 190px;
}

.calendar-hours {
  width: 72px;
  text-align: right;
}

.calendar-day {
  display: inline-grid;
  gap: 2px;
}

.calendar-day strong {
  font-size: 12px;
}

.calendar-day small {
  color: var(--muted);
}

.holiday {
  color: var(--red);
}

.short-day {
  color: var(--amber);
}

.workday {
  color: var(--green);
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(160px, 1fr));
  gap: 10px;
}

.detail {
  display: grid;
  gap: 4px;
  border-bottom: 1px solid var(--line);
  padding: 9px 0;
}

.detail span {
  color: var(--muted);
  font-size: 12px;
}

.detail strong {
  font-size: 15px;
}

.settings-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(150px, 1fr));
  gap: 12px;
}

.inline-fields {
  display: grid;
  grid-template-columns: repeat(2, minmax(130px, 1fr));
  gap: 6px;
}

.inline-form {
  display: grid;
  grid-template-columns: minmax(180px, 260px) auto;
  gap: 10px;
  align-items: end;
  margin-bottom: 12px;
}

.backup-panel {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
}

.backup-panel h2 {
  margin: 0 0 4px;
  font-size: 18px;
}

.file-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  padding: 9px 12px;
}

.file-button:hover {
  border-color: var(--line-strong);
  background: #fafbf9;
}

.file-button input {
  display: none;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  max-width: min(420px, calc(100vw - 36px));
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: var(--shadow);
  padding: 12px 14px;
  color: var(--ink);
  z-index: 20;
}

.hidden {
  display: none !important;
}

@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
    padding: 12px;
  }

  .nav {
    grid-template-columns: repeat(2, 1fr);
  }

  .kpi-grid,
  .detail-grid,
  .settings-grid,
  .filters,
  .split {
    grid-template-columns: 1fr;
  }

  .topbar {
    align-items: start;
    flex-direction: column;
  }

  .backup-panel {
    align-items: stretch;
    flex-direction: column;
  }
}

@media (max-width: 700px) {
  body {
    font-size: 13px;
  }

  .content {
    padding: 12px;
    gap: 12px;
  }

  .brand strong {
    font-size: 16px;
  }

  .sidebar {
    gap: 10px;
  }

  .nav {
    display: flex;
    gap: 6px;
    overflow-x: auto;
    padding-bottom: 2px;
  }

  .nav button {
    flex: 0 0 auto;
    width: auto;
    white-space: nowrap;
    padding: 8px 10px;
  }

  .sidebar-footer {
    grid-template-columns: 1fr auto;
    align-items: center;
  }

  .sidebar-footer button {
    min-width: 88px;
  }

  .topbar h1 {
    font-size: 20px;
  }

  .toolbar {
    width: 100%;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    align-items: end;
  }

  .toolbar label {
    min-width: 0;
  }

  .toolbar button,
  .toolbar select,
  .toolbar input {
    width: 100%;
  }

  .kpi-grid {
    gap: 8px;
  }

  .kpi {
    padding: 10px;
  }

  .kpi strong {
    font-size: 18px;
  }

  .panel-body {
    padding: 10px;
  }

  .table-wrap {
    max-height: 68vh;
  }

  .matrix-wrap {
    max-height: 72vh;
  }

  .matrix-table {
    min-width: 1220px;
    font-size: 11px;
  }

  .matrix-table th,
  .matrix-table td {
    height: 25px;
    padding: 1px 2px;
  }

  .matrix-table .matrix-employee {
    width: 158px;
    min-width: 158px;
  }

  .matrix-table .matrix-indicator {
    left: 158px;
    width: 118px;
    min-width: 118px;
  }

  .matrix-day-header {
    width: 38px;
    min-width: 38px;
  }

  .matrix-input {
    font-size: 9px;
  }

  .detail-grid {
    gap: 6px;
  }

  .detail strong {
    font-size: 14px;
  }
}

@media (max-width: 430px) {
  .login-panel {
    padding: 20px;
  }

  .toolbar {
    grid-template-columns: 1fr;
  }

  .sidebar-footer {
    grid-template-columns: 1fr;
  }
}

.employee-row {
  display: flex;
  align-items: center;
  gap: 4px;
}

.employee-row > button[data-select-employee] {
  flex: 1;
  min-width: 0;
}

.reorder-btns {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex-shrink: 0;
}

.employee-list .reorder-btn {
  display: block;
  padding: 2px 7px;
  min-height: unset;
  font-size: 12px;
  line-height: 1.5;
  border-radius: 5px;
}

.matrix-reorder {
  display: flex;
  gap: 2px;
  margin-top: 3px;
}

.matrix-reorder button {
  display: block;
  padding: 0 5px;
  min-height: unset;
  line-height: 1.5;
  font-size: 11px;
  border-radius: 4px;
}

.salary-history {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.salary-history strong {
  display: block;
  margin-bottom: 8px;
  font-size: 13px;
  color: var(--muted);
}

.salary-history table {
  width: auto;
  min-width: 280px;
}

.salary-history td {
  padding: 6px 10px;
  font-size: 13px;
}

tr.uz-holiday-row {
  background: #fff1f0;
}

tr.uz-holiday-row td {
  color: #c0392b;
}
