:root {
  color-scheme: dark;
  --bg: #080d12;
  --surface: #111820;
  --surface-2: #17212c;
  --surface-3: #1e2a36;
  --line: #334252;
  --line-soft: #263443;
  --text: #f3f7fb;
  --muted: #bdc8d5;
  --soft: #92a0af;
  --brand: #35d0ad;
  --brand-strong: #9af0db;
  --blue: #7db5ff;
  --warning: #ffd166;
  --danger: #ff8a8a;
  --ok: #84e7a8;
  --shadow: 0 18px 42px rgba(0, 0, 0, 0.32);
  font-family: "Kanit", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  background: var(--bg);
}

body {
  min-height: 100vh;
  margin: 0;
  background:
    linear-gradient(180deg, rgba(53, 208, 173, 0.07), rgba(8, 13, 18, 0) 26rem),
    var(--bg);
  color: var(--text);
  font-family: "Kanit", system-ui, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  letter-spacing: 0;
  padding-bottom: calc(8.25rem + env(safe-area-inset-bottom));
}

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

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

button {
  border: 0;
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.58;
}

a {
  color: inherit;
}

:focus-visible {
  outline: 3px solid var(--brand-strong);
  outline-offset: 3px;
}

.skip-link {
  position: absolute;
  left: 1rem;
  top: 1rem;
  z-index: 20;
  transform: translateY(-5rem);
  border-radius: 6px;
  background: var(--brand);
  color: #04110e;
  padding: 0.75rem 1rem;
  font-weight: 600;
  text-decoration: none;
}

.skip-link:focus {
  transform: translateY(0);
}

.topbar,
.app-shell,
.safe-notice {
  width: min(100%, 1120px);
  margin: 0 auto;
  padding-inline: 1rem;
}

.topbar {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  padding-top: 1.25rem;
  padding-bottom: 1rem;
}

.system-label,
.eyebrow {
  margin: 0;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 400;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: 1.8rem;
  line-height: 1.1;
  letter-spacing: 0;
}

h2 {
  margin-bottom: 0;
  font-size: 1.15rem;
  line-height: 1.25;
}

.clock-panel {
  display: grid;
  gap: 0.1rem;
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  background: rgba(17, 24, 32, 0.94);
  padding: 0.8rem 1rem;
  box-shadow: var(--shadow);
}

.clock-panel time {
  color: var(--muted);
  font-size: 0.9rem;
}

.clock-panel strong {
  font-size: 1.55rem;
  font-weight: 600;
  line-height: 1.1;
}

.app-shell {
  display: block;
}

.view {
  display: grid;
  gap: 1rem;
}

.view[hidden] {
  display: none;
}

.hero-panel,
.module-header,
.identity-strip,
.action-panel,
.timeline-panel,
.history-panel,
.empty-state {
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  background: rgba(17, 24, 32, 0.96);
  box-shadow: var(--shadow);
}

.hero-panel,
.module-header,
.action-panel,
.timeline-panel,
.history-panel,
.empty-state {
  padding: 1rem;
}

.section-heading,
.module-header {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.section-heading.compact {
  margin-bottom: 0.75rem;
}

.sample-badge,
.status-badge,
.invoice-status,
.history-status,
.partner-type {
  width: fit-content;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
  padding: 0.32rem 0.7rem;
  font-size: 0.82rem;
  line-height: 1.2;
}

.sample-badge {
  border-color: rgba(255, 209, 102, 0.45);
  color: var(--warning);
}

.summary-grid,
.shortcut-grid,
.menu-grid {
  display: grid;
  gap: 0.75rem;
}

.summary-card,
.shortcut-link,
.menu-grid a,
.approval-list li,
.timeline-item,
.history-item,
.invoice-item,
.partner-item {
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  background: var(--surface-2);
  padding: 0.9rem;
}

.summary-card {
  display: grid;
  gap: 0.35rem;
  min-height: 8.25rem;
}

.summary-card span,
.approval-list span,
.menu-grid span {
  color: var(--muted);
  font-size: 0.88rem;
}

.summary-card strong {
  color: var(--brand-strong);
  font-size: 1.05rem;
  font-weight: 600;
}

.summary-card p,
.empty-state p {
  margin-bottom: 0;
  color: var(--muted);
  font-size: 0.92rem;
}

.approval-list,
.timeline-list,
.history-list,
.invoice-list,
.partner-list {
  display: grid;
  gap: 0.65rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.approval-list li {
  display: grid;
  gap: 0.25rem;
}

.approval-list strong {
  color: var(--text);
  font-size: 0.96rem;
  font-weight: 500;
}

.shortcut-link,
.menu-grid a {
  min-height: 58px;
  color: var(--text);
  text-decoration: none;
  display: grid;
  align-content: center;
}

.shortcut-link {
  border-color: rgba(53, 208, 173, 0.26);
}

.menu-grid a {
  gap: 0.2rem;
}

.menu-grid strong {
  font-size: 1rem;
}

.module-header {
  margin-bottom: 0;
}

.segment-control {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.35rem;
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  background: #0d131a;
  padding: 0.35rem;
}

.segment-control a {
  min-height: 44px;
  border-radius: 6px;
  color: var(--muted);
  display: grid;
  place-items: center;
  text-align: center;
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 500;
}

.segment-control a[aria-selected="true"] {
  background: var(--surface-3);
  color: var(--brand-strong);
}

.empty-state {
  min-height: 14rem;
  align-content: center;
  gap: 0.5rem;
}

.identity-strip {
  display: grid;
  grid-template-columns: 3rem 1fr;
  gap: 0.85rem;
  align-items: center;
  padding: 1rem;
}

.avatar {
  display: grid;
  width: 3rem;
  height: 3rem;
  place-items: center;
  border-radius: 8px;
  background: #233244;
  color: var(--brand-strong);
  font-weight: 700;
}

.identity-strip h2 {
  margin-bottom: 0.2rem;
}

#employee-meta {
  margin-bottom: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.status-badge {
  grid-column: 1 / -1;
}

.status-badge.is-active {
  border-color: rgba(132, 231, 168, 0.45);
  color: var(--ok);
}

.status-badge.is-complete {
  border-color: rgba(154, 240, 219, 0.45);
  color: var(--brand-strong);
}

.planned-status {
  margin-bottom: 0;
  color: var(--warning);
  font-size: 0.92rem;
}

.work-meter {
  display: grid;
  gap: 0.75rem;
  border-radius: 8px;
  background: var(--surface-2);
  padding: 1rem;
  margin-bottom: 1rem;
}

.meter-copy {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  color: var(--muted);
  font-size: 0.92rem;
}

.meter-copy strong {
  color: var(--text);
  white-space: nowrap;
}

.meter-track {
  height: 0.6rem;
  overflow: hidden;
  border-radius: 999px;
  background: #263342;
}

.meter-track span {
  display: block;
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--brand), var(--blue));
  transition: width 240ms ease;
}

#attendance-form,
#invoice-form,
#partner-form {
  display: grid;
  gap: 1rem;
}

.field-group {
  display: grid;
  gap: 0.45rem;
}

label {
  color: var(--muted);
  font-size: 0.92rem;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #0d131a;
  color: var(--text);
  padding: 0.82rem 0.9rem;
}

textarea {
  min-height: 7.5rem;
  resize: vertical;
}

::placeholder {
  color: #8795a5;
}

.field-hint,
.demo-message {
  margin-bottom: 0;
  color: var(--soft);
  font-size: 0.86rem;
}

.demo-message {
  border-top: 1px solid var(--line-soft);
  margin-top: 1rem;
  padding-top: 1rem;
}

.action-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.75rem;
}

.primary-action,
.secondary-action {
  min-height: 52px;
  border-radius: 8px;
  padding: 0.82rem 1rem;
  font-weight: 600;
}

.primary-action {
  background: var(--brand);
  color: #04110e;
}

.secondary-action {
  border: 1px solid var(--line);
  background: var(--surface-3);
  color: var(--text);
}

.primary-action:not(:disabled):hover,
.secondary-action:not(:disabled):hover,
.shortcut-link:hover,
.menu-grid a:hover {
  filter: brightness(1.08);
}

.timeline-item {
  display: grid;
  gap: 0.25rem;
}

.timeline-time,
.history-date {
  color: var(--brand-strong);
  font-size: 0.85rem;
  font-weight: 500;
}

.timeline-title,
.history-title {
  margin-bottom: 0;
  color: var(--text);
  font-weight: 500;
}

.timeline-note,
.history-meta {
  margin-bottom: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.history-item {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.35rem;
}

.history-status.ok {
  color: var(--ok);
}

.history-status.warn {
  color: var(--warning);
}

.invoice-list {
  margin-top: 0.75rem;
}

.invoice-item.empty {
  color: var(--muted);
  text-align: center;
}

.invoice-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
}

.invoice-head strong {
  color: var(--text);
  font-size: 0.96rem;
}

.invoice-status.draft {
  border-color: rgba(255, 209, 102, 0.38);
  color: var(--warning);
}

.invoice-body {
  margin-top: 0.75rem;
  color: var(--muted);
  font-size: 0.9rem;
}

.invoice-body p {
  margin-bottom: 0.35rem;
}

.invoice-meta {
  color: var(--soft);
}

.invoice-actions {
  margin-top: 0.75rem;
}

.partner-list {
  margin-top: 0.75rem;
}

.partner-item.empty {
  color: var(--muted);
  text-align: center;
}

.partner-head {
  display: grid;
  gap: 0.5rem;
}

.partner-head strong {
  color: var(--text);
  font-size: 0.98rem;
  font-weight: 600;
}

.partner-type {
  border-color: rgba(125, 181, 255, 0.34);
  color: var(--blue);
}

.partner-detail {
  display: grid;
  gap: 0.3rem;
  margin-top: 0.75rem;
  color: var(--muted);
  font-size: 0.9rem;
}

.partner-detail p {
  margin-bottom: 0;
  overflow-wrap: anywhere;
}

.partner-actions {
  margin-top: 0.75rem;
}

.item-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(4.25rem, 0.35fr);
  gap: 0.5rem;
  margin-bottom: 0.6rem;
}

.item-desc {
  grid-column: 1 / -1;
}

.item-remove {
  min-height: 44px;
  border: 1px solid rgba(255, 138, 138, 0.35);
  border-radius: 8px;
  background: #2d1a1d;
  color: var(--danger);
  font-size: 0.86rem;
}

.safe-notice {
  position: fixed;
  right: 0;
  bottom: calc(4.75rem + env(safe-area-inset-bottom));
  left: 0;
  display: grid;
  gap: 0.2rem;
  border-top: 1px solid rgba(255, 209, 102, 0.32);
  background: rgba(8, 13, 18, 0.96);
  padding-top: 0.65rem;
  padding-bottom: 0.65rem;
  backdrop-filter: blur(12px);
  z-index: 8;
}

.safe-notice strong {
  color: var(--warning);
  font-weight: 600;
}

.safe-notice span {
  color: var(--muted);
  font-size: 0.84rem;
}

.bottom-tabs {
  position: fixed;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 9;
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 0.25rem;
  border-top: 1px solid var(--line-soft);
  background: rgba(10, 15, 21, 0.98);
  padding: 0.45rem 0.55rem calc(0.45rem + env(safe-area-inset-bottom));
  backdrop-filter: blur(16px);
}

.tab-link {
  min-width: 0;
  min-height: 56px;
  border-radius: 8px;
  color: var(--muted);
  display: grid;
  place-items: center;
  border: 1px solid transparent;
  padding: 0.55rem 0.35rem;
  text-align: center;
  text-decoration: none;
  font-size: 0.78rem;
  font-weight: 500;
}

.tab-link.is-active {
  border-color: var(--line);
  background: var(--surface-3);
  color: var(--text);
}

.tab-create {
  color: var(--text);
  background: rgba(53, 208, 173, 0.16);
  border-color: rgba(53, 208, 173, 0.38);
}

@media (min-width: 560px) {
  .summary-grid,
  .shortcut-grid,
  .menu-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .item-row {
    grid-template-columns: minmax(12rem, 1fr) 5rem 5.5rem 7rem 3.25rem;
  }

  .item-desc {
    grid-column: auto;
  }
}

@media (min-width: 760px) {
  body {
    padding-bottom: calc(7.75rem + env(safe-area-inset-bottom));
  }

  h1 {
    font-size: 2.35rem;
  }

  .topbar {
    flex-direction: row;
    align-items: end;
    justify-content: space-between;
    padding-top: 2rem;
  }

  .clock-panel {
    min-width: 15rem;
    text-align: right;
  }

  .dashboard-view {
    grid-template-columns: minmax(0, 1.2fr) minmax(18rem, 0.8fr);
    align-items: start;
  }

  .hero-panel {
    grid-column: 1 / -1;
  }

  .summary-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .attendance-view,
  #attendance-view {
    grid-template-columns: minmax(0, 1.15fr) minmax(18rem, 0.85fr);
    align-items: start;
  }

  .identity-strip,
  #attendance-view .action-panel {
    grid-column: 1;
  }

  .timeline-panel,
  .history-panel {
    grid-column: 2;
  }

  .identity-strip {
    grid-template-columns: 3rem 1fr auto;
  }

  .status-badge {
    grid-column: auto;
  }

  .section-heading,
  .action-grid,
  .history-item,
  .partner-head,
  .module-header {
    align-items: center;
  }

  .section-heading,
  .module-header {
    flex-direction: row;
    justify-content: space-between;
  }

  .action-grid,
  .history-item,
  .partner-head {
    grid-template-columns: 1fr auto;
  }

  #partner-form {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  #partner-form .field-group:nth-of-type(1),
  #partner-form .field-group:nth-of-type(5),
  #partner-form .field-group:nth-of-type(8),
  #partner-form .action-grid {
    grid-column: 1 / -1;
  }

  .segment-control {
    min-width: 28rem;
  }
}

@media (min-width: 1120px) {
  .bottom-tabs {
    right: 50%;
    left: 50%;
    width: min(100%, 1120px);
    transform: translateX(-50%);
    border-right: 1px solid var(--line-soft);
    border-left: 1px solid var(--line-soft);
    border-radius: 8px 8px 0 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.001ms !important;
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
  }
}
