:root {
  --bg: #f5f7f4;
  --surface: #ffffff;
  --ink: #18211f;
  --muted: #66726f;
  --line: #d9e0dc;
  --accent: #146c5f;
  --accent-strong: #0f5148;
  --warm: #c9792b;
  --blue: #4267b2;
  --shadow: 0 18px 45px rgba(27, 42, 38, 0.10);
  --card-radius: 8px;
  --section-x: 20px;
  --section-y: 18px;
  --card-x: 14px;
  --card-y: 14px;
  --details-x: 16px;
  --details-y: 16px;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, "Segoe UI", Arial, sans-serif;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 260px 1fr;
}

.app-shell[hidden] {
  display: none;
}

body:not([data-role="admin"]) [data-admin-only] {
  display: none !important;
}

.login-gate {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 24px;
  background: var(--bg);
}

.login-gate[hidden] {
  display: none;
}

.login-panel {
  width: min(420px, 100%);
  display: grid;
  gap: 16px;
  justify-items: start;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--card-radius);
  box-shadow: var(--shadow);
  padding: 28px;
}

.login-panel h1 {
  font-size: 30px;
}

.login-panel p {
  color: var(--muted);
  line-height: 1.5;
}

.sidebar {
  min-height: 100vh;
  padding: 24px 18px;
  background: #17231f;
  color: #f7fbf9;
  position: sticky;
  top: 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 32px;
}

.brand-mark {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  background: #f5c46b;
  color: #17231f;
  border-radius: var(--card-radius);
  font-weight: 800;
}

.brand-logo span {
  color: inherit;
  font-size: 8px;
  letter-spacing: 0;
  line-height: 1;
  text-transform: uppercase;
}

.eyebrow,
small,
.client-list span,
.totals span {
  color: var(--muted);
}

nav {
  display: grid;
  gap: 6px;
}

nav a {
  color: #dce8e4;
  text-decoration: none;
  padding: 12px;
  border-radius: var(--card-radius);
}

nav a.active,
nav a:hover {
  background: #253630;
}

main {
  padding: 28px;
  display: grid;
  gap: 24px;
  align-content: start;
}

.topbar,
.panel-head,
.actions,
.totals,
.account {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.account {
  justify-content: flex-end;
}

.account span {
  color: var(--muted);
  font-size: 14px;
  text-align: right;
}

.account .api-ok {
  color: var(--accent);
  font-weight: 800;
}

.account .api-offline {
  color: var(--warm);
  font-weight: 800;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 34px;
  line-height: 1.1;
}

h2 {
  font-size: 20px;
}

.eyebrow {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0;
  font-weight: 700;
}

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

button {
  border: 0;
  border-radius: var(--card-radius);
  cursor: pointer;
  font-weight: 700;
}

.signin,
.secondary {
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--line);
  padding: 10px 14px;
}

.primary {
  background: var(--accent);
  color: white;
  padding: 12px 16px;
}

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

.icon-button {
  width: 40px;
  height: 40px;
  background: var(--warm);
  color: white;
  font-size: 20px;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
}

.dashboard-welcome {
  display: grid;
  gap: 8px;
}

.summary-grid article,
.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--card-radius);
  box-shadow: var(--shadow);
}

.summary-grid article {
  padding: 18px;
  display: grid;
  grid-template-rows: minmax(40px, auto) 42px 20px;
  gap: 8px;
  min-height: 142px;
  align-items: start;
}

.summary-grid strong {
  font-size: 26px;
  align-self: center;
  line-height: 1.1;
}

.summary-grid small {
  align-self: end;
}

.view {
  display: none;
}

.view.active-view {
  display: grid;
  gap: 24px;
}

.panel {
  padding: var(--section-x);
}

.app-section-card {
  padding: 0;
}

.section-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  cursor: pointer;
  min-height: 81px;
  padding: var(--section-y) var(--section-x);
}

.section-summary::marker {
  color: var(--muted);
}

.section-summary > strong,
.settings-section > summary strong {
  color: var(--ink);
  font-size: 20px;
  line-height: 1.2;
}

.settings-section > summary small {
  color: var(--muted);
  font-size: 14px;
  line-height: 1.35;
}

.section-summary > button {
  flex: 0 0 auto;
}

.app-section-card > .form-status,
.app-section-card > .client-list,
.app-section-card > .inactive-client-list,
.app-section-card > .closed-period-list {
  margin-left: var(--section-x);
  margin-right: var(--section-x);
}

.app-section-card > .form-status {
  margin-top: 0;
}

.form-status:empty {
  display: none;
}

.app-section-card > .client-list:empty,
.app-section-card > .inactive-client-list:empty,
.app-section-card > .closed-period-list:empty {
  display: none;
}

.app-section-card > .client-list,
.app-section-card > .closed-period-list {
  margin-bottom: var(--section-x);
}

.app-section-card > .inactive-client-list {
  margin-bottom: var(--section-x);
}

form {
  margin-top: 18px;
  display: grid;
  gap: 14px;
}

.form-status {
  color: var(--muted);
  font-size: 14px;
  min-height: 20px;
}

label {
  display: grid;
  gap: 7px;
  font-size: 14px;
  font-weight: 700;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--card-radius);
  padding: 11px 12px;
  color: var(--ink);
  background: #fbfcfb;
}

input,
select,
button {
  min-height: 40px;
}

textarea {
  resize: vertical;
}

.client-list {
  margin-top: 18px;
  display: grid;
  gap: 10px;
}

.client-list article {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: var(--card-y) var(--card-x);
  border: 1px solid var(--line);
  border-radius: var(--card-radius);
}

.client-list article div {
  display: grid;
  gap: 4px;
}

.client-list b {
  color: var(--ink);
  white-space: nowrap;
}

.client-workspace {
  display: grid;
  gap: 18px;
}

.client-card {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--card-radius);
  overflow: hidden;
}

.client-card summary {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) repeat(3, minmax(110px, auto));
  gap: 14px;
  align-items: center;
  cursor: pointer;
  padding: var(--card-y) var(--card-x);
}

.client-card summary span {
  display: grid;
  gap: 4px;
}

.client-card summary strong,
.period-card summary > strong,
.period-lock-card strong {
  color: var(--ink);
  font-size: 16px;
  line-height: 1.2;
}

.client-card summary small,
.client-card summary span,
.period-card summary > span:not(.period-summary-actions),
.period-lock-card span {
  color: var(--muted);
  font-size: 14px;
  line-height: 1.35;
}

.client-card summary b,
.period-card summary b,
.period-lock-card b {
  color: var(--ink);
  font-size: 14px;
  line-height: 1.35;
}

#inactive-client-list .client-card,
#developer-inactive-list .client-card {
  background: #f8faf8;
  color: #737f7a;
}

#inactive-client-list .client-card summary span,
#inactive-client-list .client-card summary small,
#inactive-client-list .client-card summary b,
#developer-inactive-list .client-card summary span,
#developer-inactive-list .client-card summary small,
#developer-inactive-list .client-card summary b {
  color: #737f7a;
}

.client-details {
  border-top: 1px solid var(--line);
  display: grid;
  gap: 16px;
  padding: var(--details-y) var(--details-x);
}

.client-details h3,
.inactive-client-list h3 {
  margin: 0 0 8px;
  font-size: 15px;
  color: var(--ink);
}

.developer-card-actions {
  display: flex;
  gap: 10px;
  align-items: end;
}

.client-edit-form,
.inline-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(120px, 1fr));
  gap: 10px;
  align-items: end;
}

.inline-grid {
  grid-template-columns: minmax(160px, 1fr) 120px 150px 150px 110px auto;
  margin-bottom: 8px;
}

.fixed-fee-edit,
.fixed-fee-create {
  grid-template-columns: minmax(260px, 1fr) 120px 150px 150px 110px auto;
}

.paired-fields {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.paired-fields input {
  min-width: 0;
}

#period-start-form {
  grid-template-columns: minmax(180px, 260px) auto;
}

#period-start-form button {
  height: 47px;
  align-self: end;
}

.empty-line {
  color: var(--muted);
  margin: 0;
}

.inactive-client-list {
  display: grid;
  gap: 12px;
  margin-top: 18px;
}

.statement-panel {
  display: grid;
  gap: 18px;
}

.notice {
  box-shadow: none;
}

.notice p {
  margin-top: 8px;
  color: var(--muted);
  line-height: 1.55;
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 720px;
}

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

th {
  color: var(--muted);
  font-size: 13px;
}

.totals {
  border-top: 1px solid var(--line);
  padding-top: 16px;
}

.totals div {
  display: grid;
  gap: 5px;
}

.totals strong {
  font-size: 20px;
}

.admin-grid {
  display: grid;
  grid-template-columns: minmax(360px, 1.2fr) minmax(320px, 0.8fr);
  gap: 18px;
  align-items: start;
}

.settings-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(320px, 1fr));
  gap: 18px;
  align-items: start;
}

.settings-stack {
  display: grid;
  gap: 14px;
}

.settings-section {
  padding: 0;
}

.settings-section > summary {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  cursor: pointer;
  min-height: 81px;
  padding: var(--section-y) var(--section-x);
}

.settings-section > summary span {
  display: grid;
  gap: 4px;
}

.settings-section-body {
  border-top: 1px solid var(--line);
  padding: var(--details-y) var(--details-x);
}

.settings-wide {
  grid-column: 1 / -1;
}

.checkbox-line {
  grid-template-columns: 20px 1fr;
  align-items: center;
  font-weight: 700;
}

.checkbox-line input {
  width: 18px;
  height: 18px;
}

td input,
td select {
  min-width: 150px;
  padding: 8px 10px;
  height: 40px;
}

.table-check {
  display: flex;
  grid-template-columns: none;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  white-space: nowrap;
}

.table-check input {
  min-width: 0;
  width: 16px;
  height: 16px;
}

.time-create-form {
  grid-template-columns: 150px minmax(150px, 1fr) minmax(150px, 1fr) minmax(220px, 1.4fr) 122px 142px;
  align-items: end;
}

.time-create-form textarea {
  min-height: 40px;
  height: 40px;
  resize: vertical;
}

.time-parts-field {
  gap: 8px;
}

.time-parts {
  display: grid;
  grid-template-columns: 58px 58px;
  gap: 6px;
  width: 122px;
}

.time-parts input {
  min-width: 0;
  width: 58px;
}

.time-create-submit {
  width: 142px;
}

.developer-form-grid {
  grid-template-columns: repeat(4, minmax(160px, 1fr));
  align-items: end;
}

.developer-form-grid button,
.developer-form-grid .form-status {
  align-self: end;
}

.time-create-form .form-status {
  grid-column: 1 / -1;
}

.row-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  white-space: nowrap;
}

.row-actions button {
  height: 40px;
  padding: 8px 12px;
}

.period-card {
  border: 1px solid var(--line);
  border-radius: var(--card-radius);
  overflow: hidden;
}

.period-card summary {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  padding: var(--card-y) var(--card-x);
  cursor: pointer;
}

.period-card summary > strong {
  order: 1;
}

.period-card summary > span:not(.period-summary-actions) {
  order: 2;
}

.developer-work-period .period-summary-values {
  display: grid;
  grid-template-columns: repeat(2, minmax(100px, auto));
  gap: 14px;
  justify-content: end;
  text-align: right;
}

.period-card summary > .period-summary-actions {
  order: 3;
  display: flex;
  gap: 8px;
  flex-wrap: nowrap;
  margin-left: auto;
}

.period-card summary > .period-summary-actions button {
  flex: 0 0 auto;
  white-space: nowrap;
}

.period-lock-card {
  align-items: center;
  display: grid !important;
  grid-template-columns: minmax(180px, 1fr) minmax(120px, auto) auto;
}

.period-lock-card button {
  justify-self: end;
  min-height: 40px;
}

.period-card .table-wrap {
  border-top: 1px solid var(--line);
  padding: 0 var(--details-x) var(--details-y);
}

.statement-period-details {
  display: grid;
  gap: 14px;
  padding: var(--details-y) var(--details-x);
  border-top: 1px solid var(--line);
}

.statement-period-details .table-wrap {
  padding: 0;
  border-top: 0;
}

.closed-period-list {
  display: grid;
  gap: 10px;
}

.api-ok,
td .api-ok {
  color: var(--accent);
  font-weight: 800;
}

.api-offline,
td .api-offline {
  color: var(--warm);
  font-weight: 800;
}

@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: clamp(178px, 28vw, 220px) minmax(0, 1fr);
  }

  .sidebar {
    min-height: 100vh;
    padding: 20px 12px;
    position: sticky;
    top: 0;
  }

  .brand {
    gap: 10px;
    margin-bottom: 24px;
  }

  .brand-mark {
    height: 38px;
    width: 38px;
  }

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

  nav {
    grid-template-columns: 1fr;
  }

  nav a {
    min-height: 40px;
    padding: 10px;
    font-size: clamp(12px, 1.45vw, 14px);
    line-height: 1.2;
    overflow-wrap: anywhere;
  }

  .summary-grid,
  .admin-grid,
  .settings-grid {
    grid-template-columns: 1fr 1fr;
  }
}

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

  .sidebar {
    min-height: auto;
    padding: 16px;
    position: static;
  }

  .brand {
    margin-bottom: 16px;
  }

  nav a {
    min-height: 38px;
    padding: 9px 10px;
    font-size: 13px;
  }

  main {
    padding: 18px;
  }

  .topbar,
  .panel-head,
  .client-list article,
  .totals,
  .account {
    align-items: stretch;
    flex-direction: column;
  }

  .account span {
    text-align: left;
  }

  h1 {
    font-size: 28px;
  }

  .summary-grid,
  .admin-grid,
    .settings-grid,
    .client-card summary,
    .client-edit-form,
    .inline-grid,
    .paired-fields,
    .time-create-form,
    .developer-form-grid {
    grid-template-columns: 1fr;
  }

  .time-create-submit {
    width: 100%;
  }

  .settings-wide {
    grid-column: auto;
  }

  .client-list b {
    white-space: normal;
  }

  .actions {
    width: 100%;
  }

  .actions button {
    flex: 1;
  }

  .developer-card-actions {
    flex-direction: column;
    align-items: stretch;
  }
}
