:root {
  --bg: #f4f6f8;
  --panel: #ffffff;
  --ink: #1f2933;
  --muted: #667085;
  --line: #d9e0e7;
  --brand: #0f766e;
  --brand-strong: #115e59;
  --accent: #2563eb;
  --danger: #b42318;
  --warning: #b54708;
  --success: #067647;
  --shadow: 0 18px 50px rgba(31, 41, 51, 0.08);
}

* {
  box-sizing: border-box;
}

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

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

button {
  cursor: pointer;
}

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

.login-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-card {
  width: min(420px, 100%);
  display: grid;
  gap: 14px;
  padding: 24px;
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.login-brand {
  margin-bottom: 8px;
}

.login-hint {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.sidebar {
  background: #111827;
  color: #f9fafb;
  display: flex;
  flex-direction: column;
  padding: 24px;
}

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

.brand-mark {
  width: 44px;
  height: 44px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: var(--brand);
  font-weight: 800;
}

.brand strong,
.brand span {
  display: block;
}

.brand span,
.sidebar-footer span {
  color: #aeb8c4;
  font-size: 13px;
}

.nav {
  display: grid;
  gap: 8px;
}

.nav-item {
  height: 44px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: #cbd5e1;
  text-align: left;
  padding: 0 14px;
}

.nav-item.active,
.nav-item:hover {
  background: #243044;
  color: #ffffff;
}

.sidebar-footer {
  margin-top: auto;
  border-top: 1px solid #334155;
  padding-top: 18px;
  display: grid;
  gap: 6px;
}

.main {
  min-width: 0;
  padding: 26px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: center;
  margin-bottom: 22px;
}

.topbar h1 {
  margin: 0 0 4px;
  font-size: 28px;
  letter-spacing: 0;
}

.topbar p {
  margin: 0;
  color: var(--muted);
}

.top-actions,
.form-actions,
.task-actions,
.client-actions {
  display: flex;
  gap: 10px;
  align-items: center;
}

.primary-button,
.ghost-button,
.danger-button {
  min-height: 40px;
  border-radius: 8px;
  padding: 0 14px;
  border: 1px solid transparent;
  font-weight: 700;
}

.primary-button {
  background: var(--brand);
  color: #ffffff;
}

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

.ghost-button {
  background: #ffffff;
  border-color: var(--line);
  color: var(--ink);
}

.danger-button {
  background: #fff1f0;
  color: var(--danger);
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 16px;
}

.finance-summary {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 16px;
}

.alert {
  margin-bottom: 16px;
  padding: 13px 14px;
  border: 1px solid #fecdca;
  border-radius: 8px;
  background: #fff1f0;
  color: var(--danger);
  font-weight: 700;
}

.metric,
.panel,
.form-panel,
.client-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.metric {
  padding: 18px;
}

.metric span {
  color: var(--muted);
  font-size: 13px;
}

.metric strong {
  display: block;
  margin-top: 8px;
  font-size: 30px;
}

.metric.urgent strong {
  color: var(--danger);
}

.content-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.6fr) minmax(280px, 0.7fr);
  gap: 16px;
}

.templates-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  margin-bottom: 16px;
}

.templates-lists {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.panel {
  padding: 18px;
  min-width: 0;
}

.panel.large {
  grid-row: span 2;
}

.panel-heading {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  margin-bottom: 14px;
}

.panel-heading h2,
.form-panel h2,
dialog h2 {
  margin: 0;
  font-size: 18px;
}

.task-list,
.certificate-list,
.activity-list,
.client-list {
  display: grid;
  gap: 10px;
}

.task-card {
  display: grid;
  grid-template-columns: 62px minmax(0, 1fr);
  gap: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-left: 4px solid var(--accent);
  border-radius: 8px;
}

.task-card.late {
  border-left-color: var(--danger);
}

.task-card.soon {
  border-left-color: var(--warning);
}

.task-card.done {
  opacity: 0.72;
}

.task-date {
  height: 58px;
  border-radius: 8px;
  background: #eef4ff;
  display: grid;
  place-items: center;
  align-content: center;
}

.task-date strong {
  font-size: 22px;
}

.task-date span {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

.task-body {
  min-width: 0;
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.task-body h3,
.client-card h3 {
  margin: 0 0 5px;
  font-size: 16px;
}

.task-body p,
.client-card p,
.client-card small,
td small {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.task-actions {
  grid-column: 2;
  justify-content: flex-start;
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  border-radius: 999px;
  padding: 0 10px;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.pill.pending,
.pill.doing,
.pill.open,
.pill.requested {
  background: #eef4ff;
  color: #1849a9;
}

.pill.waiting {
  background: #fff6ed;
  color: var(--warning);
}

.pill.done,
.pill.paid,
.pill.sent {
  background: #ecfdf3;
  color: var(--success);
}

.pill.overdue {
  background: #fff1f0;
  color: var(--danger);
}

.pill.neutral {
  background: #f2f4f7;
  color: #475467;
}

.certificate-card,
.activity-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
}

.certificate-card {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.certificate-card span,
.certificate-card small,
.activity-item small {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.certificate-card.soon small,
.certificate-card.late small {
  color: var(--danger);
  font-weight: 700;
}

.activity-item {
  display: grid;
  gap: 5px;
}

.scroll-list {
  max-height: 260px;
  overflow-y: auto;
  padding-right: 4px;
}

.scroll-list::-webkit-scrollbar {
  width: 8px;
}

.scroll-list::-webkit-scrollbar-thumb {
  background: #cbd5e1;
  border-radius: 8px;
}

.alert-item {
  border-color: #fedf89;
  background: #fffbeb;
}

.toolbar {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) 220px 190px;
  gap: 12px;
  margin-bottom: 14px;
}

.finance-toolbar {
  grid-template-columns: minmax(220px, 1fr) 220px 170px 170px;
}

.process-toolbar {
  grid-template-columns: minmax(220px, 1fr) 220px 170px 190px;
}

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

textarea {
  resize: vertical;
}

.table-wrap {
  overflow: auto;
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

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

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

th {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

td strong,
td small {
  display: block;
}

.late {
  color: var(--danger);
}

.soon {
  color: var(--warning);
}

.done {
  color: var(--success);
}

.text-button {
  border: 0;
  background: transparent;
  color: var(--accent);
  font-weight: 700;
  padding: 0;
}

.client-layout {
  display: grid;
  grid-template-columns: 360px minmax(0, 1fr);
  gap: 16px;
}

.form-panel {
  padding: 18px;
  display: grid;
  gap: 12px;
  align-self: start;
}

label {
  display: grid;
  gap: 6px;
  color: #344054;
  font-size: 13px;
  font-weight: 700;
}

.client-card {
  padding: 16px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
}

.client-meta {
  text-align: right;
}

.client-meta span,
.client-meta strong,
.client-meta small {
  display: block;
}

.client-meta span,
.client-meta small {
  color: var(--muted);
  font-size: 13px;
}

.client-actions {
  grid-column: 1 / -1;
}

.template-list,
.attachment-list {
  display: grid;
  gap: 10px;
}

.template-card,
.attachment-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto auto;
  gap: 10px;
  align-items: center;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.template-card span,
.attachment-item span {
  display: block;
  color: var(--muted);
  font-size: 13px;
}

.attachment-item a {
  color: var(--accent);
  font-weight: 700;
  text-decoration: none;
}

.check-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.check-row input {
  width: auto;
  min-height: auto;
}

.certificate-download {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
  color: var(--muted);
  font-size: 13px;
}

.certificate-download a {
  color: var(--accent);
  font-weight: 700;
  text-decoration: none;
  white-space: nowrap;
}

dialog {
  width: min(620px, calc(100vw - 28px));
  border: 0;
  border-radius: 8px;
  padding: 0;
  box-shadow: 0 30px 80px rgba(15, 23, 42, 0.28);
}

dialog::backdrop {
  background: rgba(15, 23, 42, 0.45);
}

dialog form {
  padding: 20px;
  display: grid;
  gap: 13px;
}

.dialog-heading,
.form-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  align-items: center;
}

.form-row {
  grid-template-columns: 1fr 1fr;
}

.icon-button {
  width: 36px;
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  font-size: 22px;
  line-height: 1;
}

.empty {
  color: var(--muted);
  padding: 16px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  text-align: center;
}

.toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  background: #111827;
  color: #ffffff;
  border-radius: 8px;
  padding: 12px 14px;
  opacity: 0;
  transform: translateY(10px);
  pointer-events: none;
  transition: 180ms ease;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

[hidden] {
  display: none !important;
}

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

  .sidebar {
    position: sticky;
    top: 0;
    z-index: 2;
    padding: 14px;
  }

  .brand,
  .sidebar-footer {
    display: none;
  }

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

  .nav-item {
    text-align: center;
    padding: 0 8px;
  }

  .metrics,
  .finance-summary,
  .templates-grid,
  .templates-lists,
  .content-grid,
  .toolbar {
    grid-template-columns: 1fr;
  }

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

  .top-actions {
    flex-wrap: wrap;
  }
}

@media (max-width: 640px) {
  .main {
    padding: 16px;
  }

  .metrics {
    gap: 10px;
  }

  .task-card,
  .client-card,
  .template-card,
  .form-row {
    grid-template-columns: 1fr;
  }

  .task-actions {
    grid-column: 1;
    flex-wrap: wrap;
  }

  .task-body,
  .certificate-card {
    flex-direction: column;
  }
}
