:root {
  --bg: #eef2f3;
  --panel: #ffffff;
  --ink: #16212a;
  --muted: #66717c;
  --line: #d9e0e5;
  --navy: #1e3a4a;
  --teal: #0f766e;
  --teal-dark: #112f32;
  --olive: #39412d;
  --gold: #b7791f;
  --gold-soft: #f6d34b;
  --red: #b42318;
  --green: #16703b;
  --shadow: 0 18px 42px rgba(16, 31, 45, 0.11);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

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

html {
  scroll-behavior: smooth;
}

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

.topbar {
  align-items: center;
  background: linear-gradient(135deg, #0d2029 0%, #15343a 55%, #2f3527 100%);
  border-bottom: 4px solid var(--gold-soft);
  color: #fff;
  display: flex;
  justify-content: space-between;
  min-height: 118px;
  padding: 18px clamp(18px, 4vw, 42px);
  gap: 20px;
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand-block {
  align-items: center;
  display: flex;
  gap: 16px;
  min-width: 260px;
}

.brand-logo {
  background: #071116;
  border: 2px solid rgba(246, 211, 75, 0.76);
  border-radius: 50%;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.24);
  height: 74px;
  object-fit: contain;
  padding: 4px;
  width: 74px;
}

.eyebrow {
  color: #96c9c3;
  font-size: 0.77rem;
  font-weight: 700;
  letter-spacing: 0;
  margin: 0 0 6px;
  text-transform: uppercase;
}

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

h1 {
  font-size: clamp(1.6rem, 4vw, 2.45rem);
  line-height: 1.12;
  margin-bottom: 0;
}

h2 {
  font-size: 1.1rem;
  margin-bottom: 4px;
}

h3 {
  font-size: 0.95rem;
  margin-bottom: 10px;
}

.top-actions,
.filters,
.two-col {
  display: flex;
  gap: 10px;
}

.top-actions {
  flex-wrap: wrap;
  justify-content: flex-end;
}

.action-menu {
  display: block;
  position: relative;
}

.action-menu summary {
  cursor: pointer;
  display: flex;
  justify-content: center;
  list-style: none;
}

.action-menu summary::-webkit-details-marker {
  display: none;
}

.action-menu-panel {
  background: #13262d;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 8px;
  box-shadow: var(--shadow);
  display: none;
  gap: 10px;
  grid-template-columns: repeat(2, minmax(120px, 1fr));
  padding: 10px;
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  width: min(360px, 90vw);
  z-index: 30;
}

.action-menu[open] .action-menu-panel {
  display: grid;
}

.action-menu-panel .ghost-btn,
.action-menu-panel .file-btn {
  justify-content: center;
  width: 100%;
}

.app-shell {
  padding: 22px clamp(14px, 3vw, 34px) 38px;
}

.workspace-layout {
  align-items: start;
  display: grid;
  gap: 18px;
  grid-template-columns: 220px minmax(0, 1fr);
}

.workspace-main {
  min-width: 0;
}

.sidebar {
  background: #13262d;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 8px;
  box-shadow: var(--shadow);
  display: grid;
  gap: 4px;
  padding: 14px;
  position: sticky;
  top: 142px;
}

.sidebar-title {
  color: #9fc8c2;
  font-size: 0.75rem;
  font-weight: 800;
  margin-bottom: 8px;
  text-transform: uppercase;
}

.sidebar a,
.nav-tab {
  border-radius: 6px;
  background: transparent;
  border: 0;
  color: #e8f1ef;
  cursor: pointer;
  font-size: 0.92rem;
  font-weight: 800;
  padding: 10px 11px;
  text-align: left;
  text-decoration: none;
}

.sidebar a:hover,
.sidebar a:focus,
.nav-tab:hover,
.nav-tab:focus,
.nav-tab.active {
  background: rgba(246, 211, 75, 0.14);
  color: #fff7c7;
  outline: none;
}

.view-panel[hidden] {
  display: none;
}

.dashboard {
  display: grid;
  gap: 14px;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  margin-bottom: 18px;
}

.period-summary {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  margin-bottom: 18px;
  overflow: hidden;
}

.period-controls label {
  min-width: 150px;
}

.period-metrics {
  border-top: 1px solid var(--line);
  display: grid;
  gap: 0;
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.responsible-metrics {
  grid-template-columns: repeat(6, minmax(0, 1fr));
}

.responsible-controls label {
  min-width: min(360px, 100%);
}

.responsible-grid .summary-card canvas {
  max-height: 300px;
}

.period-metrics article {
  border-right: 1px solid var(--line);
  padding: 15px 20px;
}

.period-metrics article:last-child {
  border-right: 0;
}

.period-metrics span {
  color: var(--muted);
  display: block;
  font-size: 0.78rem;
  font-weight: 800;
  margin-bottom: 6px;
  text-transform: uppercase;
}

.period-metrics strong {
  font-size: 1.7rem;
}

.summary-grid {
  border-top: 1px solid var(--line);
  display: grid;
  gap: 14px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  padding: 16px;
}

.summary-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  min-width: 0;
  padding: 12px;
}

.summary-card-wide {
  grid-column: 1 / -1;
}

.summary-card h3 {
  color: #26343d;
  font-size: 0.95rem;
  margin-bottom: 8px;
}

.summary-card canvas {
  max-height: 320px;
}

.compliance-grid,
.notification-list {
  display: grid;
  gap: 10px;
}

.compliance-grid {
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
}

.compliance-item,
.notification-item {
  align-items: flex-start;
  border: 1px solid var(--line);
  border-radius: 8px;
  display: flex;
  gap: 10px;
  padding: 11px 12px;
}

.compliance-item span {
  border-radius: 50%;
  flex: 0 0 13px;
  height: 13px;
  margin-top: 4px;
  width: 13px;
}

.compliance-item.ok span {
  background: var(--green);
}

.compliance-item.warn span {
  background: var(--gold);
}

.compliance-item.danger span {
  background: var(--red);
}

.compliance-item small,
.notification-item span {
  color: var(--muted);
  display: block;
  font-size: 0.82rem;
  margin-top: 3px;
}

.notification-section {
  margin-bottom: 18px;
}

.notification-list {
  border-top: 1px solid var(--line);
  padding: 14px 18px 18px;
}

.notification-item {
  border-left: 5px solid #2563eb;
}

.notification-item.warn {
  border-left-color: var(--gold);
}

.notification-item.danger {
  border-left-color: var(--red);
}

.notification-empty {
  color: var(--muted);
  padding: 4px 0;
}

.calendar-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.calendar-grid {
  border-top: 1px solid var(--line);
  display: grid;
  grid-template-columns: repeat(7, minmax(120px, 1fr));
  grid-auto-rows: minmax(108px, auto);
  overflow-x: auto;
}

.calendar-head,
.calendar-cell {
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  min-height: 108px;
  padding: 9px;
  overflow: visible;
}

.calendar-head {
  background: #e8eef0;
  color: #2f3a43;
  font-size: 0.78rem;
  font-weight: 900;
  min-height: 36px;
  text-transform: uppercase;
}

.calendar-cell.muted-day {
  background: #f7faf9;
  color: #8b98a3;
}

.calendar-date {
  font-weight: 900;
  margin-bottom: 6px;
}

.calendar-task {
  border-radius: 5px;
  color: #fff;
  font-size: 0.72rem;
  font-weight: 800;
  margin-bottom: 4px;
  overflow-wrap: anywhere;
  padding: 4px 5px;
  white-space: normal;
}

.calendar-task.done {
  background: var(--teal);
}

.calendar-task.due {
  background: var(--red);
}

.calendar-task.pending {
  background: var(--gold);
  color: #17212a;
}

.calendar-more {
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 800;
}

.metric {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  min-height: 92px;
  padding: 18px;
  position: relative;
  overflow: hidden;
}

.metric::before {
  background: var(--teal);
  content: "";
  inset: 0 auto 0 0;
  position: absolute;
  width: 5px;
}

.metric-total::before {
  background: var(--navy);
}

.metric-done::before {
  background: var(--green);
}

.metric-pending::before {
  background: var(--gold);
}

.metric-high::before,
.metric-overdue::before {
  background: var(--red);
}

.metric span {
  color: var(--muted);
  display: block;
  font-size: 0.83rem;
  margin-bottom: 8px;
}

.metric strong {
  font-size: 2rem;
  line-height: 1;
}

.content-grid {
  display: grid;
  gap: 18px;
  grid-template-columns: minmax(330px, 440px) minmax(0, 1fr);
  margin-bottom: 18px;
}

.task-form,
.insights-panel,
.records-section {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.task-form,
.insights-panel {
  padding: 20px;
}

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

.section-title p {
  color: var(--muted);
  font-size: 0.87rem;
  margin-bottom: 0;
}

label {
  color: #43505b;
  display: grid;
  font-size: 0.82rem;
  font-weight: 700;
  gap: 6px;
}

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

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

input:focus,
select:focus,
textarea:focus {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.16);
  outline: none;
}

.primary-btn,
.ghost-btn,
.icon-btn,
.small-btn {
  align-items: center;
  border: 0;
  border-radius: 6px;
  cursor: pointer;
  display: inline-flex;
  font-weight: 800;
  justify-content: center;
  min-height: 40px;
  padding: 9px 13px;
  white-space: nowrap;
}

.primary-btn {
  background: #147c72;
  color: #fff;
}

.primary-btn:hover {
  background: #0f665e;
}

.ghost-btn {
  background: rgba(255, 255, 255, 0.11);
  border: 1px solid rgba(255, 255, 255, 0.28);
  color: #fff;
  gap: 7px;
}

.ghost-btn:disabled {
  cursor: not-allowed;
  opacity: 0.52;
}

.status-pill {
  align-items: center;
  align-self: center;
  background: rgba(255, 255, 255, 0.14);
  border: 1px solid rgba(255, 255, 255, 0.28);
  border-radius: 999px;
  color: #fff;
  display: inline-flex;
  font-size: 0.82rem;
  font-weight: 800;
  min-height: 40px;
  padding: 8px 12px;
}

.status-pill.online {
  background: #dcfce7;
  border-color: #bbf7d0;
  color: var(--green);
}

.setup-notice {
  background: #fff7ed;
  border: 1px solid #fed7aa;
  border-radius: 8px;
  color: #7c2d12;
  margin-bottom: 18px;
  padding: 13px 16px;
}

.setup-notice code {
  background: rgba(124, 45, 18, 0.08);
  border-radius: 4px;
  padding: 2px 5px;
}

.auth-gate {
  display: grid;
  min-height: 58vh;
  place-items: center;
}

.auth-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  display: grid;
  gap: 14px;
  max-width: 420px;
  padding: 22px;
  width: min(100%, 420px);
}

.auth-message {
  color: var(--red);
  font-size: 0.88rem;
  font-weight: 700;
  margin: 0;
  min-height: 20px;
}

.file-btn input {
  display: none;
}

.chart-wrap {
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  padding: 10px;
}

canvas {
  display: block;
  height: auto;
  max-width: 100%;
  width: 100%;
}

.recent-box {
  margin-top: 16px;
}

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

#recentList li {
  border-left: 3px solid var(--teal);
  color: #33414c;
  font-size: 0.88rem;
  padding: 5px 0 5px 10px;
}

.records-section {
  overflow: hidden;
  scroll-margin-top: 150px;
}

.admin-section {
  margin-bottom: 18px;
}

.records-header {
  align-items: end;
  display: flex;
  gap: 18px;
  justify-content: space-between;
  padding: 18px 20px;
}

.filters {
  align-items: end;
  flex-wrap: wrap;
}

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

.inline-form label {
  min-width: min(360px, 100%);
}

.personnel-list {
  border-top: 1px solid var(--line);
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(auto-fit, minmax(330px, 1fr));
  padding: 12px;
}

.personnel-item {
  align-items: flex-start;
  border: 1px solid var(--line);
  border-radius: 6px;
  display: flex;
  gap: 10px;
  justify-content: space-between;
  margin: 0;
  min-height: 58px;
  padding: 11px 12px;
}

.personnel-item span {
  font-size: 0.88rem;
  font-weight: 800;
  line-height: 1.25;
  min-width: 0;
  overflow-wrap: anywhere;
  padding-top: 4px;
}

.personnel-item .small-btn {
  flex: 0 0 auto;
}

.filters label {
  min-width: 170px;
}

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

table {
  border-collapse: separate;
  border-spacing: 0;
  min-width: 1280px;
  width: 100%;
}

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

th {
  background: #e8eef0;
  color: #2f3a43;
  font-size: 0.78rem;
  position: sticky;
  top: 0;
  text-transform: uppercase;
  z-index: 1;
}

td {
  font-size: 0.9rem;
}

tbody tr {
  transition: background 0.14s ease, box-shadow 0.14s ease;
}

tbody tr:hover {
  background: #f7faf9;
}

tbody tr td:first-child {
  border-left: 5px solid transparent;
}

.row-done td:first-child {
  border-left-color: var(--green);
}

.row-pending td:first-child {
  border-left-color: var(--gold);
}

.row-running td:first-child {
  border-left-color: #2563eb;
}

.row-issue td:first-child,
.row-overdue td:first-child {
  border-left-color: var(--red);
}

.task-cell {
  max-width: 320px;
}

.muted {
  color: var(--muted);
}

.empty-cell {
  color: var(--muted);
  font-weight: 700;
  padding: 18px !important;
  text-align: center;
}

.badge {
  border-radius: 999px;
  display: inline-flex;
  font-size: 0.78rem;
  font-weight: 800;
  padding: 4px 9px;
}

.badge.done {
  background: #dcfce7;
  color: var(--green);
}

.badge.pending {
  background: #fef3c7;
  color: var(--gold);
}

.badge.review {
  background: #dbeafe;
  color: #1d4ed8;
}

.badge.running {
  background: #dbeafe;
  color: #1d4ed8;
}

.badge.issue {
  background: #fee4e2;
  color: var(--red);
}

.badge.closed {
  background: #e5e7eb;
  color: #374151;
}

.badge.high {
  background: #fee4e2;
  color: var(--red);
}

.row-actions {
  display: flex;
  gap: 7px;
  flex-wrap: wrap;
}

.small-btn {
  background: #eef3f4;
  color: #24333d;
  min-height: 34px;
  padding: 7px 10px;
}

.small-btn.active {
  background: #d7f7ef;
  color: var(--teal);
}

.small-btn.danger {
  background: #fee4e2;
  color: var(--red);
}

dialog {
  border: 0;
  border-radius: 8px;
  box-shadow: 0 25px 70px rgba(16, 31, 45, 0.28);
  max-width: 640px;
  padding: 0;
  width: min(92vw, 640px);
}

dialog::backdrop {
  background: rgba(17, 37, 48, 0.45);
}

.dialog-card {
  padding: 20px;
}

.dialog-head {
  align-items: center;
  display: flex;
  justify-content: space-between;
  gap: 10px;
}

.icon-btn {
  background: #eef3f4;
  color: #24333d;
  font-size: 1.2rem;
  min-width: 40px;
  padding: 6px;
}

.dialog-content {
  color: #2e3b45;
  display: grid;
  gap: 10px;
  line-height: 1.45;
}

.dialog-content div {
  border-top: 1px solid var(--line);
  padding-top: 10px;
}

.report-actions {
  border-top: 0 !important;
  display: flex;
  justify-content: flex-end;
  padding: 0 0 12px;
}

.report-preview {
  background: #fff;
  color: var(--ink);
}

.report-preview h1 {
  color: var(--navy);
  font-size: 1.35rem;
  margin-bottom: 8px;
}

.report-preview p {
  color: var(--muted);
  font-size: 0.88rem;
  margin-bottom: 14px;
}

.report-preview table {
  border-collapse: collapse;
  font-size: 0.78rem;
  width: 100%;
}

.report-preview th,
.report-preview td {
  border: 1px solid var(--line);
  padding: 7px;
  text-align: left;
  vertical-align: top;
}

.report-preview th {
  background: #edf2f4;
  color: var(--navy);
}

@media print {
  body.print-report-mode .topbar,
  body.print-report-mode .sidebar,
  body.print-report-mode .filters,
  body.print-report-mode .top-actions,
  body.print-report-mode .actions-cell,
  body.print-report-mode .notification-section,
  body.print-report-mode .admin-section,
  body.print-report-mode .calendar-actions,
  body.print-report-mode .dialog-head,
  body.print-report-mode .report-actions {
    display: none !important;
  }

  body.print-report-mode {
    background: #fff;
  }

  body.print-report-mode dialog {
    border: 0;
    box-shadow: none;
    display: block;
    inset: auto;
    margin: 0;
    max-height: none;
    max-width: none;
    padding: 0;
    position: static;
    width: 100%;
  }

  body.print-report-mode dialog::backdrop {
    display: none;
  }

  body.print-report-mode .dialog-card {
    box-shadow: none;
    padding: 0;
  }

  body.print-report-mode .dialog-content {
    display: block;
    max-height: none;
    overflow: visible;
  }
}

@media (max-width: 980px) {
  .topbar,
  .records-header {
    align-items: stretch;
    flex-direction: column;
  }

  .top-actions {
    justify-content: flex-start;
  }

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

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

  .workspace-layout {
    grid-template-columns: 1fr;
  }

  .period-metrics,
  .responsible-metrics,
  .summary-grid {
    grid-template-columns: 1fr 1fr;
  }

  .calendar-grid {
    grid-template-columns: repeat(7, minmax(150px, 1fr));
  }

  .summary-card-wide {
    grid-column: 1 / -1;
  }

  .sidebar {
    display: flex;
    overflow-x: auto;
    position: static;
  }

  .sidebar-title {
    display: none;
  }
}

@media (max-width: 640px) {
  .topbar {
    gap: 10px;
    min-height: 0;
    padding: 10px 12px;
    position: sticky;
  }

  .brand-block {
    gap: 10px;
    min-width: 0;
    width: 100%;
  }

  .brand-block h1 {
    font-size: 1.18rem;
    line-height: 1.08;
  }

  .eyebrow {
    font-size: 0.65rem;
    margin-bottom: 3px;
  }

  .top-actions {
    align-items: stretch;
    display: grid;
    gap: 7px;
    grid-template-columns: 1fr 1fr;
    width: 100%;
  }

  .top-actions .status-pill,
  .top-actions .ghost-btn,
  .action-menu summary {
    min-height: 36px;
    padding: 8px 9px;
  }

  #userEmail {
    font-size: 0.72rem;
    grid-column: 1 / -1;
    max-width: none;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .action-menu {
    display: block;
    grid-column: 1 / -1;
    position: relative;
  }

  .action-menu summary {
    display: flex;
    justify-content: center;
    width: 100%;
  }

  .action-menu-panel {
    background: #13262d;
    border: 1px solid rgba(255, 255, 255, 0.16);
    border-radius: 8px;
    box-shadow: var(--shadow);
    display: none;
    gap: 7px;
    grid-template-columns: 1fr 1fr;
    margin-top: 7px;
    padding: 8px;
    position: static;
    width: 100%;
  }

  .action-menu[open] .action-menu-panel {
    display: grid;
  }

  .action-menu-panel .ghost-btn,
  .action-menu-panel .file-btn {
    justify-content: center;
    width: 100%;
  }

  .app-shell {
    padding: 12px 8px 28px;
  }

  .sidebar {
    gap: 6px;
    margin: 0 -2px;
    padding: 8px;
  }

  .sidebar a,
  .nav-tab {
    flex: 0 0 auto;
    font-size: 0.82rem;
    padding: 8px 10px;
    white-space: nowrap;
  }

  .dashboard,
  .two-col {
    grid-template-columns: 1fr;
  }

  .two-col {
    display: grid;
  }

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

  .filters label {
    min-width: 0;
  }

  .period-metrics,
  .responsible-metrics,
  .summary-grid {
    grid-template-columns: 1fr;
  }

  .brand-block {
    align-items: flex-start;
  }

  .brand-logo {
    height: 46px;
    width: 46px;
  }

  .records-section,
  .period-summary,
  .task-form,
  .insights-panel,
  .metric {
    border-radius: 6px;
  }

  .table-wrap {
    overflow: visible;
  }

  table {
    min-width: 0;
  }

  thead {
    display: none;
  }

  table,
  tbody,
  tr,
  td {
    display: block;
    width: 100%;
  }

  tbody tr {
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: 0 8px 22px rgba(16, 31, 45, 0.08);
    margin: 0 0 12px;
    overflow: hidden;
  }

  tbody tr td:first-child {
    border-left: 0;
  }

  td {
    align-items: flex-start;
    border-top: 1px solid var(--line);
    display: grid;
    gap: 8px;
    grid-template-columns: 104px minmax(0, 1fr);
    padding: 10px 12px;
  }

  td::before {
    color: var(--muted);
    content: attr(data-label);
    font-size: 0.72rem;
    font-weight: 900;
    text-transform: uppercase;
  }

  td[colspan] {
    display: block;
  }

  td[colspan]::before {
    content: "";
    display: none;
  }

  .task-cell {
    max-width: none;
  }

  .row-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    width: 100%;
  }

  .row-actions .small-btn {
    justify-content: center;
    width: 100%;
  }

  canvas {
    max-width: 100%;
  }
}
