:root {
  --bg: #f4f8fb;
  --surface: #ffffff;
  --surface-strong: #eaf4fb;
  --text: #252a78;
  --muted: #5f6f85;
  --border: #d7e5ef;
  --accent: #3298d5;
  --accent-dark: #252a78;
  --steel: #3298d5;
  --brand-dark: #252a78;
  --brand-light: #3298d5;
  --green: #16784b;
  --warning: #a76505;
  --shadow: 0 16px 40px rgba(37, 42, 120, 0.08);
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  letter-spacing: 0;
}

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

button {
  cursor: pointer;
}

.app-shell {
  min-height: 100vh;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

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

.brand-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 6px;
  background: var(--brand-dark);
  color: #fff;
  font-weight: 800;
}

.brand h1 {
  color: var(--brand-dark);
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: 20px;
  line-height: 1.2;
}

h2 {
  font-size: 16px;
  line-height: 1.3;
}

h3 {
  font-size: 14px;
  line-height: 1.35;
}

p {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.session {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.employee-month {
  display: grid;
  grid-template-columns: minmax(260px, 0.8fr) minmax(360px, 1.2fr);
  gap: 14px;
  align-items: stretch;
  padding: 16px 24px;
  background: #fff8e6;
  border-bottom: 1px solid #ead39c;
}

.employee-month-main,
.month-leaderboard {
  border: 1px solid #ead39c;
  border-radius: var(--radius);
  background: #fffdf7;
}

.employee-month-main {
  display: grid;
  align-content: center;
  gap: 5px;
  padding: 14px 16px;
}

.employee-month-main strong {
  color: var(--brand-dark);
  font-size: 22px;
  line-height: 1.2;
}

.employee-month-main > span:last-child {
  color: #785b14;
  font-size: 13px;
  font-weight: 800;
}

.month-leaderboard {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 8px;
  padding: 10px;
}

.leaderboard-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-width: 0;
  padding: 8px 10px;
  border: 1px solid #f0dfb3;
  border-radius: 6px;
  background: #ffffff;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.leaderboard-row.is-leading {
  border-color: #d9a628;
  color: var(--text);
}

.leaderboard-row > span:first-child {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.star-score {
  flex: 0 0 auto;
  color: #b58205;
  white-space: nowrap;
}

.main-grid {
  display: grid;
  grid-template-columns: 260px minmax(360px, 1fr) 380px;
  gap: 18px;
  padding: 18px 24px 24px;
}

.sidebar,
.detail-panel {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.panel,
.detail-panel,
.content {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.panel {
  padding: 16px;
}

.compact-panel,
.stats-panel,
.employee-panel {
  box-shadow: none;
}

.panel-heading,
.toolbar,
.detail-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.panel-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.collapsible-panel {
  display: grid;
  gap: 12px;
}

.panel-body {
  display: grid;
  gap: 12px;
}

.collapsible-panel.is-collapsed {
  gap: 0;
}

.collapsible-panel.is-collapsed .panel-body {
  display: none;
}

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

input,
select,
textarea {
  width: 100%;
  min-height: 40px;
  padding: 9px 10px;
  color: var(--text);
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 6px;
  outline: none;
}

textarea {
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--steel);
  box-shadow: 0 0 0 3px rgba(50, 152, 213, 0.16);
}

.compact-panel {
  gap: 12px;
  display: grid;
}

.stat-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  color: var(--muted);
  font-size: 13px;
}

.stat-row:last-child {
  border-bottom: 0;
}

.stat-row strong {
  color: var(--text);
  font-size: 18px;
}

.content {
  min-width: 0;
  overflow: hidden;
}

.toolbar {
  padding: 16px;
  border-bottom: 1px solid var(--border);
}

.toolbar-actions,
.detail-actions,
.dialog-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}

.detail-actions {
  position: sticky;
  bottom: 0;
  z-index: 2;
  padding-top: 10px;
  background: var(--surface);
}

.primary-button,
.secondary-button,
.icon-button {
  min-height: 38px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 800;
}

.primary-button {
  border: 1px solid var(--steel);
  background: var(--steel);
  color: #fff;
  padding: 0 14px;
}

.primary-button:hover {
  background: #287fb8;
}

.secondary-button {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  padding: 0 14px;
}

.secondary-button:hover {
  background: var(--surface-strong);
}

.icon-button {
  display: grid;
  place-items: center;
  width: 38px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
}

.task-list {
  display: grid;
}

.task-row {
  display: grid;
  grid-template-columns:
    minmax(220px, 1.7fr)
    minmax(104px, 0.72fr)
    minmax(156px, 0.88fr)
    minmax(132px, 0.9fr)
    minmax(96px, 0.65fr);
  gap: 12px;
  align-items: center;
  width: 100%;
  padding: 14px 16px;
  border: 0;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  color: inherit;
  text-align: left;
}

.task-row > * {
  min-width: 0;
}

.task-row:hover,
.task-row.is-selected {
  background: #f6fbff;
}

.task-row.is-selected {
  box-shadow: inset 4px 0 0 var(--steel);
}

.task-title {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.task-title strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 14px;
}

.task-title span,
.task-meta {
  overflow: hidden;
  color: var(--muted);
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12px;
}

.chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 26px;
  min-width: 0;
  width: min(100%, fit-content);
  max-width: 100%;
  padding: 0 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.chip {
  overflow: hidden;
  text-overflow: ellipsis;
}

.chip.urgent {
  background: #e9f4fb;
  color: var(--accent-dark);
}

.chip.normal {
  background: #e8f4fc;
  color: var(--steel);
}

.chip.later {
  background: #fff2d9;
  color: var(--warning);
}

.chip.open {
  background: #edf0f2;
  color: #515c65;
}

.chip.progress {
  background: #e8f4fc;
  color: var(--steel);
}

.chip.done {
  background: #e2f5eb;
  color: var(--green);
}

.chip.archived {
  background: #ece7df;
  color: #5e5143;
}

.detail-panel {
  padding: 16px;
  min-height: 520px;
}

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

.field-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.attachment-box {
  display: grid;
  gap: 10px;
  padding: 12px;
  background: #f6fbff;
  border: 1px solid var(--border);
  border-radius: 6px;
}

.attachment-head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: end;
}

.attachment-note {
  font-size: 12px;
}

.image-preview {
  display: grid;
  gap: 8px;
  margin: 0;
}

.image-preview img {
  display: block;
  width: 100%;
  max-height: 220px;
  object-fit: cover;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
}

.image-preview figcaption {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  overflow-wrap: anywhere;
}

.section-label {
  color: var(--muted);
  font-size: 11px;
  font-weight: 900;
  text-transform: uppercase;
}

.completion-box {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  padding: 12px;
  background: var(--surface-strong);
  border-radius: 6px;
}

.completion-box span {
  display: block;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
}

.completion-box strong {
  display: block;
  margin-top: 4px;
  font-size: 13px;
}

.self-assign-box {
  display: grid;
  gap: 12px;
  padding: 14px;
  background: #fff8e6;
  border: 1px solid #ead39c;
  border-radius: 6px;
}

.self-assign-controls {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) auto;
  gap: 10px;
  align-items: end;
}

.self-assign-controls .primary-button {
  min-width: 150px;
}

.assignee-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.assignee-empty {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.empty-state {
  display: grid;
  align-content: center;
  min-height: 480px;
  gap: 8px;
  padding: 18px;
  text-align: center;
}

.admin-app {
  padding: 18px 24px 24px;
}

.admin-app-shell {
  display: grid;
  gap: 18px;
  max-width: 1180px;
  margin: 0 auto;
  padding: 18px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.admin-app-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.admin-app-header h2 {
  margin-top: 4px;
  font-size: 20px;
}

.admin-overview {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
}

.admin-overview-card {
  display: grid;
  gap: 6px;
  min-height: 92px;
  padding: 14px;
  background: var(--surface-strong);
  border: 1px solid var(--border);
  border-radius: 6px;
}

.admin-overview-card span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.admin-overview-card strong {
  color: var(--text);
  font-size: 28px;
  line-height: 1;
}

.admin-grid,
.user-lists {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

#employeeForm,
#accountForm {
  display: grid;
  gap: 10px;
  align-content: start;
}

ul {
  display: grid;
  gap: 8px;
  margin: 10px 0 0;
  padding: 0;
  list-style: none;
}

li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 9px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
}

dialog {
  width: min(420px, calc(100vw - 32px));
  padding: 0;
  border: 0;
  border-radius: 8px;
  box-shadow: 0 24px 80px rgba(37, 42, 120, 0.24);
}

dialog::backdrop {
  background: rgba(37, 42, 120, 0.42);
}

.login-card {
  display: grid;
  gap: 14px;
  padding: 20px;
}

.toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 50;
  max-width: 360px;
  padding: 12px 14px;
  border-radius: 6px;
  background: var(--text);
  color: #fff;
  font-size: 13px;
  font-weight: 800;
  box-shadow: var(--shadow);
}

.install-prompt {
  position: fixed;
  right: 14px;
  bottom: 14px;
  left: 14px;
  z-index: 35;
  display: none;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  max-width: 620px;
  margin: 0 auto;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 18px 50px rgba(37, 42, 120, 0.18);
}

.install-prompt:not(.hidden) {
  display: grid;
}

.install-prompt strong {
  display: block;
  color: var(--brand-dark);
  font-size: 15px;
  line-height: 1.25;
}

.install-prompt p {
  margin-top: 3px;
  font-size: 12px;
}

.install-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.hidden {
  display: none !important;
}

.danger-text {
  color: var(--accent);
}

@media (max-width: 1180px) {
  .main-grid {
    grid-template-columns: 240px minmax(360px, 1fr);
  }

  .task-row {
    grid-template-columns: minmax(0, 1fr) minmax(120px, auto);
    gap: 8px 12px;
  }

  .task-title {
    grid-column: 1 / -1;
  }

  .task-row .chip {
    justify-self: start;
  }

  .task-row .task-meta {
    min-width: 0;
    white-space: normal;
  }

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

@media (max-width: 760px) {
  .topbar,
  .toolbar,
  .main-grid {
    padding-left: 14px;
    padding-right: 14px;
  }

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

  .employee-month {
    grid-template-columns: 1fr;
    padding-left: 14px;
    padding-right: 14px;
  }

  .main-grid {
    display: grid;
    grid-template-columns: 1fr;
  }

  body.detail-overlay-open {
    overflow: hidden;
  }

  body.detail-overlay-open::before {
    content: "";
    position: fixed;
    inset: 0;
    z-index: 30;
    background: rgba(16, 28, 48, 0.54);
  }

  .detail-panel {
    display: none;
    position: fixed;
    inset: 12px;
    z-index: 40;
    min-height: 0;
    max-height: calc(100dvh - 24px);
    overflow-y: auto;
    overscroll-behavior: contain;
  }

  .detail-panel.is-open {
    display: flex;
  }

  .detail-panel.is-open .detail-header {
    position: sticky;
    top: -16px;
    z-index: 1;
    padding-top: 16px;
    padding-bottom: 10px;
    background: var(--surface);
  }

  .detail-panel .empty-state {
    min-height: 260px;
  }

  .task-row {
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .task-title strong,
  .task-title span,
  .task-meta {
    white-space: normal;
  }

  .field-grid,
  .attachment-head,
  .completion-box,
  .self-assign-controls,
  .admin-grid,
  .user-lists {
    grid-template-columns: 1fr;
  }

  .toolbar-actions,
  .detail-actions {
    width: 100%;
  }

  .toolbar-actions > *,
  .detail-actions > * {
    flex: 1 1 150px;
  }

  .admin-app {
    padding: 14px;
  }

  .admin-app-shell {
    padding: 14px;
  }

  .admin-app-header {
    align-items: flex-start;
  }

  body:has(.install-prompt:not(.hidden)) {
    padding-bottom: 96px;
  }

  .install-prompt {
    grid-template-columns: 1fr;
  }

  .install-actions {
    width: 100%;
  }

  .install-actions .primary-button {
    flex: 1;
  }
}
