:root {
  --bg: #f5f3ec;
  --surface: #ffffff;
  --surface-soft: #fbfaf6;
  --ink: #172033;
  --muted: #657083;
  --line: #e4dfd2;
  --brand: #b88217;
  --brand-dark: #8b640f;
  --accent: #176b5d;
  --danger: #a63838;
  --shadow: 0 14px 34px rgba(35, 37, 42, 0.09);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at 12% -10%, rgba(184, 130, 23, 0.16), transparent 32%),
    linear-gradient(180deg, #fbfaf6 0%, var(--bg) 100%);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.loading-screen {
  position: fixed;
  z-index: 1100;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 18px;
  background: var(--bg);
}

.loading-screen.hidden {
  display: none;
}

.loading-panel {
  display: grid;
  justify-items: center;
  gap: 12px;
  color: var(--ink);
  text-align: center;
}

.loading-panel span:last-child {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.loading-spinner {
  width: 36px;
  height: 36px;
  border: 4px solid var(--line);
  border-top-color: var(--brand);
  border-radius: 50%;
  animation: loading-spin 0.8s linear infinite;
}

@keyframes loading-spin {
  to {
    transform: rotate(360deg);
  }
}

.login-screen {
  position: fixed;
  z-index: 1000;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(245, 243, 236, 0.96);
}

.login-screen.hidden {
  display: none;
}

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

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

.login-panel label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.login-message {
  min-height: 20px;
  margin: 0;
  color: var(--danger);
  font-size: 13px;
}

.form-message {
  min-height: 18px;
  margin: 0;
  color: var(--danger);
  font-size: 12px;
  font-weight: 800;
}

.sync-status {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.sync-status[data-status="saved"] {
  color: var(--accent);
}

.sync-status[data-status="error"] {
  color: var(--danger);
}

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

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 24px clamp(18px, 4vw, 48px) 14px;
}

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

.brand-logo {
  width: 72px;
  height: 72px;
  border: 2px solid rgba(215, 168, 60, 0.72);
  border-radius: 50%;
  object-fit: cover;
  background: #fff;
  box-shadow: 0 12px 28px rgba(35, 37, 42, 0.16);
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--brand);
  font-size: 13px;
  font-weight: 800;
  text-transform: uppercase;
}

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

h1 {
  margin-bottom: 0;
  font-size: clamp(24px, 3vw, 34px);
  line-height: 1.05;
}

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

.app-shell {
  padding: 0 clamp(18px, 4vw, 48px) 40px;
}

.month-panel {
  width: min(720px, 100%);
  display: grid;
  grid-template-columns: 46px minmax(180px, 280px) 46px 1fr;
  gap: 10px;
  align-items: end;
  margin: 0 auto 14px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.82);
  box-shadow: var(--shadow);
}

.month-panel label {
  display: grid;
  gap: 5px;
}

.month-panel span,
.month-panel strong {
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
}

.month-panel strong {
  align-self: center;
  color: var(--brand);
  font-size: 14px;
}

.month-nav {
  min-height: 44px;
  border: 1px solid rgba(215, 168, 60, 0.45);
  border-radius: 8px;
  background: rgba(215, 168, 60, 0.14);
  color: var(--brand);
  font-size: 28px;
  font-weight: 900;
  cursor: pointer;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin: 0 auto 16px;
}

.summary-grid article {
  min-height: 92px;
  padding: 18px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.summary-grid span,
.search-field span,
.section-head p,
.selected-partner p {
  color: var(--muted);
  font-size: 13px;
}

.summary-grid strong {
  display: block;
  margin-top: 8px;
  color: var(--ink);
  font-size: 28px;
}

.workspace {
  max-width: 1480px;
  margin: 0 auto;
}

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

.sidebar {
  margin: 16px;
  padding: 16px;
  background: var(--surface-soft);
  position: static;
}

.sidebar.hidden {
  display: none;
}

.section-head {
  display: flex;
  justify-content: space-between;
  gap: 16px;
}

.section-head h2,
.content-panel h2 {
  margin-bottom: 4px;
  font-size: 18px;
}

.search-field {
  display: grid;
  gap: 6px;
}

.search-field.wide {
  min-width: min(420px, 100%);
  flex: 1;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 11px 12px;
  background: #f8faf8;
  color: #172033;
  outline: none;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(215, 168, 60, 0.18);
}

.partner-list {
  display: flex;
  overflow-x: auto;
  gap: 8px;
  margin-top: 14px;
}

.partner-item {
  width: min(260px, 82vw);
  min-width: 220px;
  display: grid;
  gap: 3px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  color: var(--ink);
  text-align: left;
  cursor: pointer;
}

.partner-item.active {
  border-color: var(--brand);
  background: #fff7df;
}

.partner-item strong {
  font-size: 15px;
}

.partner-item span {
  color: var(--muted);
  font-size: 12px;
}

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

.tabs {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 8px;
  padding: 16px 16px 0;
}

.main-tabs {
  background: #fffdf8;
}

.sub-tabs {
  padding-top: 8px;
}

.tab {
  border: 0;
  border-bottom: 3px solid transparent;
  padding: 10px 8px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

.tab.active {
  border-color: var(--brand);
  color: var(--ink);
  font-weight: 800;
}

.toolbar {
  display: flex;
  align-items: end;
  gap: 10px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}

.toolbar select {
  max-width: 220px;
}

.primary-action,
.secondary-action,
.danger-action,
.icon-button {
  min-height: 42px;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 0 14px;
  font-weight: 800;
  cursor: pointer;
}

.primary-action {
  background: var(--brand);
  color: #10131a;
}

.primary-action:hover {
  background: var(--brand-dark);
}

.secondary-action {
  background: #f2f0e9;
  border-color: var(--line);
  color: var(--ink);
}

.danger-action {
  background: #fff1f1;
  border-color: #f0c8c8;
  color: var(--danger);
}

.icon-button {
  width: 42px;
  padding: 0;
  background: #f2f0e9;
  color: var(--ink);
  font-size: 24px;
  line-height: 1;
}

.selected-partner {
  display: none;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  background: #fffdf8;
}

.selected-partner.visible {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
}

.partner-actions,
.inline-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}

.selected-partner h2 {
  margin: 0 0 4px;
}

.selected-partner p {
  margin: 0;
}

.partner-notes {
  max-width: 760px;
  margin-top: 12px;
  border-left: 3px solid var(--brand);
  padding: 9px 12px;
  background: #fff7df;
}

.partner-notes strong {
  display: block;
  margin-bottom: 4px;
  font-size: 12px;
  text-transform: uppercase;
}

.partner-notes p {
  white-space: pre-wrap;
}

.course-table-wrap {
  width: 100%;
  overflow-x: auto;
}

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

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

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

td strong {
  display: block;
}

td small {
  color: var(--muted);
}

.course-detail-cell {
  min-width: 340px;
}

.course-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 8px 0 4px;
}

.course-meta span {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px 9px;
  background: #fffdf8;
  color: var(--muted);
  font-size: 12px;
}

.course-meta b {
  margin-right: 4px;
  color: var(--ink);
}

.margin-pill {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  border-radius: 999px;
  padding: 0 10px;
  background: #fff2c6;
  color: var(--brand);
  font-weight: 800;
}

.row-action {
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  color: var(--ink);
  cursor: pointer;
}

.link-action {
  min-height: 30px;
  border: 1px solid #b9d0c7;
  border-radius: 8px;
  padding: 0 10px;
  background: rgba(31, 143, 123, 0.14);
  color: #91f1dc;
  font-size: 12px;
  font-weight: 900;
  cursor: pointer;
}

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

.action-cell {
  white-space: nowrap;
}

.add-sale-action {
  width: 34px;
  min-height: 34px;
  margin-right: 6px;
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: #ffffff;
  font-size: 20px;
  font-weight: 900;
  cursor: pointer;
}

.sales-head {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 16px 8px;
}

.sales-head h2 {
  margin-bottom: 4px;
}

.sales-head p {
  margin-bottom: 0;
  color: var(--muted);
  font-size: 13px;
}

.sales-totals {
  display: grid;
  grid-template-columns: repeat(5, minmax(125px, 1fr));
  min-width: min(100%, 760px);
  font-size: 13px;
  font-weight: 900;
  text-align: center;
  gap: 6px;
}

.sales-totals div {
  overflow: hidden;
  border: 2px solid #000;
  border-radius: 6px;
}

.sales-totals small {
  display: block;
  min-height: 30px;
  padding: 6px 8px;
  background: #000;
  color: #fff;
  font-size: 11px;
  text-transform: uppercase;
}

.sales-totals span {
  display: block;
  padding: 7px 10px;
  background: #fff200;
  color: #000;
}

.report-filters {
  display: grid;
  grid-template-columns: repeat(4, minmax(150px, 1fr)) auto;
  gap: 10px;
  align-items: end;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  background: #fffdf8;
}

.report-filters label {
  display: grid;
  gap: 6px;
}

.report-filters span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.report-filters .secondary-action {
  min-width: 120px;
}

.sales-table-wrap {
  width: 100%;
  overflow-x: auto;
  padding: 0 16px 18px;
}

.sales-table {
  min-width: 1620px;
  border-collapse: collapse;
  border: 2px solid #000;
  font-size: 13px;
}

.sales-table th,
.sales-table td,
.expense-table th,
.expense-table td {
  border: 2px solid #000;
  padding: 8px 10px;
  text-align: center;
  vertical-align: middle;
  font-weight: 800;
}

.sales-table th,
.expense-table th {
  background: #143d57;
  color: #fff;
  font-size: 14px;
}

.sales-table tbody tr,
.expense-table tbody tr {
  height: 30px;
}

.sales-table tbody tr:nth-child(even) td:not(.money-cell) {
  background: #f2f5f4;
}

.sales-table .cost-cell {
  background: #f6b567;
  color: #111;
}

.sales-table .sale-cell {
  background: #6798e2;
  color: #111;
}

.sales-table .commission-cell,
.expense-table .expense-cell {
  background: #f2d477;
  color: #111;
}

.sales-table .profit-cell,
.sales-table .final-profit-cell {
  background: #94c47d;
  color: #111;
}

.expense-table {
  min-width: 980px;
  border-collapse: collapse;
  border: 2px solid #000;
  font-size: 13px;
}

.cost-summary {
  display: grid;
  grid-template-columns: repeat(3, minmax(150px, 1fr));
  gap: 10px;
  min-width: min(100%, 600px);
}

.cost-summary article {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: var(--surface-soft);
}

.cost-summary span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.cost-summary strong {
  display: block;
  margin-top: 6px;
  font-size: 20px;
}

.document-workspace {
  padding: 18px 16px;
}

.document-toolbar,
.data-backup {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 16px;
  padding-bottom: 16px;
}

.document-toolbar label,
.contract-editor-label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

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

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

.contract-editor {
  min-height: 520px;
  resize: vertical;
  background: #f8faf8;
  color: #1d2522;
  font-family: "Segoe UI", sans-serif;
  line-height: 1.5;
}

.attachments-panel,
.data-backup {
  margin-top: 18px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}

.document-list {
  display: grid;
  gap: 8px;
}

.document-item,
.exam-course-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: var(--surface-soft);
}

.document-item.compact {
  min-height: 38px;
  padding: 7px 9px;
}

.saved-file-line {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.saved-file-line .file-note {
  margin: 0;
}

.remove-file-action {
  display: inline-flex;
  width: 30px;
  min-width: 30px;
  min-height: 30px;
  align-items: center;
  justify-content: center;
  border: 1px solid #f0c8c8;
  border-radius: 8px;
  padding: 0;
  background: #fff1f1;
  color: var(--danger);
  font-weight: 900;
  cursor: pointer;
}

.edit-attachments {
  display: grid;
  gap: 8px;
  border-top: 1px solid var(--line);
  padding-top: 12px;
}

.edit-attachments h3 {
  margin: 0;
  font-size: 14px;
}

.attachment-group-title {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

.exam-course-list {
  display: grid;
  gap: 10px;
  padding: 16px;
}

.exam-course-item div:first-child {
  display: grid;
  gap: 3px;
}

.exam-course-item span,
.exam-course-item small,
.data-backup p {
  color: var(--muted);
  font-size: 12px;
}

.file-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.file-action input {
  display: none;
}

.marketing-list {
  display: grid;
  gap: 20px;
  padding: 16px;
}

.marketing-category {
  display: grid;
  gap: 10px;
}

.marketing-category h2 {
  margin: 0;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--line);
}

.marketing-category-list {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.marketing-item {
  min-width: 0;
  display: grid;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: var(--surface-soft);
}

.marketing-item div:first-child {
  min-width: 0;
  display: grid;
  gap: 4px;
}

.marketing-item strong,
.marketing-item span {
  overflow-wrap: anywhere;
}

.marketing-item span {
  color: var(--muted);
  font-size: 12px;
}

.empty-state {
  display: none;
  padding: 42px 16px;
  color: var(--muted);
  text-align: center;
}

.empty-state.visible {
  display: block;
}

dialog {
  width: min(620px, calc(100vw - 28px));
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0;
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow);
}

dialog::backdrop {
  background: rgba(12, 22, 19, 0.42);
}

dialog form {
  display: grid;
  gap: 14px;
  padding: 18px;
}

dialog header,
dialog menu {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 0;
  padding: 0;
}

dialog h2 {
  margin: 0;
}

dialog label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.file-note {
  margin: -4px 0 0;
  color: var(--muted);
  font-size: 12px;
}

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

@media (max-width: 920px) {
  .summary-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

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

  .sidebar {
    position: static;
  }

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

  .cost-summary {
    grid-template-columns: 1fr;
  }

  .document-toolbar,
  .data-backup {
    align-items: stretch;
    flex-direction: column;
  }

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

@media (max-width: 640px) {
  .topbar,
  .top-actions,
  .toolbar,
  .sales-head,
  .selected-partner.visible {
    align-items: stretch;
    flex-direction: column;
  }

  .summary-grid,
  .form-grid,
  .report-filters {
    grid-template-columns: 1fr;
  }

  .toolbar select {
    max-width: none;
  }

  .sales-totals {
    grid-template-columns: 1fr;
  }

  .document-item,
  .exam-course-item {
    align-items: stretch;
    flex-direction: column;
  }

  .marketing-category-list {
    grid-template-columns: 1fr;
  }
}
