:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --panel: #ffffff;
  --panel-2: #eef3f6;
  --text: #1f2933;
  --muted: #607080;
  --line: #d7e0e7;
  --accent: #0f766e;
  --accent-strong: #115e59;
  --warning: #b45309;
  --danger: #b42318;
  --shadow: 0 18px 48px rgba(31, 41, 51, 0.14);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: var(--text);
  background: var(--bg);
}

html {
  -webkit-text-size-adjust: 100%;
}

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

input,
select,
textarea {
  font-size: 16px;
}

.login-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
  background: #e8eef2;
}

.login-shell {
  width: min(420px, calc(100vw - 32px));
}

.login-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 28px;
  box-shadow: var(--shadow);
}

.login-mark {
  color: var(--accent-strong);
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.08em;
}

.login-panel h1 {
  margin: 8px 0 22px;
  font-size: 30px;
}

.login-panel label {
  display: grid;
  gap: 7px;
  margin-bottom: 14px;
  color: var(--muted);
  font-size: 14px;
}

.login-panel input,
.search-box input,
.tools select,
.client-form input,
.client-form textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  padding: 10px 12px;
}

.login-panel button,
.drawer-close,
.segmented button {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  cursor: pointer;
  padding: 10px 14px;
}

.ui-icon {
  width: 18px;
  height: 18px;
  flex: 0 0 18px;
  fill: currentColor;
}

.login-panel button {
  width: 100%;
  margin-top: 8px;
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 700;
}

.login-error {
  margin: 0 0 16px;
  color: var(--danger);
  font-weight: 700;
}

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

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 20px;
  padding: 20px 16px;
  background: #16232c;
  color: #dce7ed;
}

.brand {
  display: grid;
  gap: 4px;
  padding: 6px 8px 16px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
}

.brand strong {
  font-size: 18px;
}

.brand span,
.logout {
  color: #a9bac5;
  font-size: 13px;
}

.brand em {
  width: fit-content;
  border: 1px solid rgba(147, 183, 176, 0.35);
  border-radius: 999px;
  color: #dce7ed;
  font-size: 12px;
  font-style: normal;
  margin-top: 5px;
  padding: 4px 8px;
}

.section-nav {
  display: grid;
  gap: 4px;
  overflow: auto;
}

.section-nav button {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  width: 100%;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: #dce7ed;
  cursor: pointer;
  padding: 9px 10px;
  text-align: left;
}

.nav-label {
  display: inline-flex;
  align-items: center;
  min-width: 0;
  gap: 9px;
}

.nav-label .ui-icon {
  color: #93b7b0;
}

.nav-label span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.section-nav button.active,
.section-nav button:hover {
  background: rgba(255, 255, 255, 0.1);
}

.section-nav span:last-child {
  color: #9fb3bf;
  font-size: 12px;
}

.logout {
  margin-top: auto;
  padding: 10px;
  text-decoration: none;
}

.workspace {
  min-width: 0;
  padding: 22px;
}

.topbar {
  display: grid;
  grid-template-columns: minmax(240px, 1fr) minmax(320px, 520px) auto;
  gap: 20px;
  align-items: end;
}

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

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

.metrics {
  display: grid;
  grid-template-columns: repeat(6, minmax(120px, 1fr));
  gap: 12px;
  margin: 20px 0;
}

.metric {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
}

.metric strong {
  display: block;
  font-size: 24px;
}

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

.tools {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 12px;
}

.segmented {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.segmented button.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.tools select {
  max-width: 230px;
}

.content-table {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

.table-head,
.row {
  display: grid;
  grid-template-columns: minmax(210px, 1.2fr) minmax(160px, 0.9fr) minmax(170px, 0.8fr) minmax(220px, 1.2fr) 96px;
  gap: 12px;
  align-items: center;
}

.table-head {
  background: var(--panel-2);
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  padding: 10px 14px;
  text-transform: uppercase;
}

.table-body {
  max-height: calc(100vh - 278px);
  overflow: auto;
}

.row {
  min-height: 58px;
  border-top: 1px solid var(--line);
  padding: 11px 14px;
}

.row:hover {
  background: #f8fafb;
}

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

.title-cell strong,
.field-muted,
.cell-text {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.title-cell small,
.field-muted,
.tag {
  color: var(--muted);
  font-size: 12px;
}

.tags {
  display: flex;
  gap: 5px;
  flex-wrap: wrap;
}

.tag {
  background: #edf5f3;
  border: 1px solid #cfe2dd;
  border-radius: 999px;
  color: #285f58;
  padding: 3px 8px;
}

.open-btn {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  cursor: pointer;
  min-height: 36px;
  padding: 7px 9px;
}

.primary-action,
.danger-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid transparent;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 700;
  padding: 10px 14px;
}

.primary-action {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.danger-action {
  background: #fff;
  border-color: #f2b8b5;
  color: var(--danger);
}

.primary-action[hidden] {
  display: none;
}

.empty-state {
  padding: 30px;
  color: var(--muted);
  text-align: center;
}

.empty-state.compact {
  padding: 18px;
  text-align: left;
}

.studio-dashboard {
  display: grid;
  gap: 16px;
  padding: 16px;
}

.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(150px, 1fr));
  gap: 12px;
}

.dashboard-card {
  display: grid;
  gap: 6px;
  min-height: 118px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  cursor: pointer;
  padding: 14px;
  text-align: left;
}

.card-icon {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  background: #edf5f3;
  color: var(--accent-strong);
  fill: currentColor;
  padding: 7px;
}

.dashboard-card.warning .card-icon {
  background: #f7e7cd;
  color: var(--warning);
}

.dashboard-card:hover,
.mini-row:hover {
  border-color: #9fc8c0;
  background: #f5faf8;
}

.dashboard-card span,
.dashboard-card small,
.mini-row small {
  color: var(--muted);
  font-size: 12px;
}

.dashboard-card strong {
  font-size: 30px;
  line-height: 1;
}

.dashboard-card.warning {
  border-color: #efc58c;
  background: #fff8ed;
}

.work-panels {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.work-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  overflow: hidden;
}

.panel-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  border-bottom: 1px solid var(--line);
  background: var(--panel-2);
  padding: 12px;
}

.panel-title h3 {
  margin: 0;
  font-size: 15px;
}

.mini-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  border: 0;
  border-top: 1px solid var(--line);
  background: #fff;
  color: var(--text);
  cursor: pointer;
  padding: 11px 12px;
  text-align: left;
}

.mini-row:first-of-type {
  border-top: 0;
}

.mini-row span {
  display: grid;
  gap: 3px;
  min-width: 0;
}

.mini-row strong,
.mini-row small {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mini-row b {
  color: var(--accent-strong);
  font-size: 13px;
  white-space: nowrap;
}

.module-placeholder {
  display: grid;
  gap: 16px;
  padding: 18px;
}

.module-hero {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 14px;
  align-items: start;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 18px;
}

.module-icon {
  width: 42px;
  height: 42px;
  border-radius: 8px;
  background: #edf5f3;
  color: var(--accent-strong);
  fill: currentColor;
  padding: 9px;
}

.module-hero h2 {
  margin: 0 0 6px;
  font-size: 22px;
}

.module-hero p,
.module-note {
  margin: 0;
  color: var(--muted);
  line-height: 1.5;
}

.module-checklist {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.module-checklist span {
  border: 1px solid #cfe2dd;
  border-radius: 999px;
  background: #edf5f3;
  color: #285f58;
  font-size: 13px;
  padding: 6px 10px;
}

.module-note {
  border-left: 3px solid var(--accent);
  background: #f5faf8;
  border-radius: 4px;
  padding: 12px;
}

.drawer-backdrop {
  position: fixed;
  inset: 0;
  display: none;
  background: rgba(22, 35, 44, 0.28);
}

.drawer {
  position: fixed;
  top: 0;
  right: 0;
  z-index: 3;
  width: min(680px, 96vw);
  height: 100vh;
  padding: 18px;
  overflow: auto;
  background: var(--panel);
  box-shadow: var(--shadow);
  transform: translateX(105%);
  transition: transform 180ms ease;
}

.drawer.open {
  transform: translateX(0);
}

.drawer-backdrop.open {
  display: block;
}

.drawer-close {
  float: right;
}

.drawer h2 {
  margin: 8px 90px 4px 0;
  font-size: 24px;
}

.drawer-actions,
.form-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 14px;
}

.drawer-section {
  clear: both;
  margin-top: 20px;
}

.drawer-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.field {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 9px;
}

.field span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 4px;
}

.client-form {
  clear: both;
  margin-top: 18px;
}

.form-field {
  display: grid;
  gap: 5px;
}

.form-field.wide {
  grid-column: 1 / -1;
}

.form-field span,
.form-status {
  color: var(--muted);
  font-size: 12px;
}

.client-form textarea {
  min-height: 86px;
  resize: vertical;
}

.form-status {
  min-height: 18px;
  margin-top: 8px;
}

.note {
  border-left: 3px solid var(--warning);
  background: #fff8ed;
  border-radius: 4px;
  margin: 8px 0;
  padding: 10px;
  white-space: pre-wrap;
}

.link-list {
  display: grid;
  gap: 7px;
}

.link-list a {
  color: var(--accent-strong);
  overflow-wrap: anywhere;
}

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

.file-item {
  display: flex;
  align-items: center;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--text);
  padding: 10px;
  text-decoration: none;
}

.file-item:hover {
  background: #f5faf8;
  border-color: #9fc8c0;
}

.file-item span {
  display: grid;
  gap: 3px;
  min-width: 0;
}

.file-item strong,
.file-item small {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

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

.link-editor {
  display: grid;
  gap: 8px;
}

.link-edit-head,
.link-edit-row {
  display: grid;
  grid-template-columns: minmax(110px, 0.8fr) minmax(130px, 1fr) minmax(180px, 1.5fr);
  gap: 8px;
}

.link-edit-head {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.link-edit-row input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px 12px;
}

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

.access-row {
  display: flex;
  align-items: center;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  cursor: pointer;
  padding: 10px;
}

.access-row:hover {
  background: #f5faf8;
}

.access-row.is-all {
  background: #f7fbfa;
  color: var(--muted);
  cursor: default;
}

.access-row input {
  width: 18px;
  height: 18px;
  flex: 0 0 18px;
}

.access-row span {
  display: grid;
  gap: 2px;
}

.access-row small {
  color: var(--muted);
  font-size: 12px;
}

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

  .sidebar {
    position: sticky;
    top: 0;
    z-index: 2;
    height: auto;
    gap: 12px;
    padding: 12px;
  }

  .brand {
    align-items: center;
    grid-template-columns: 1fr auto;
    padding: 0 2px 10px;
  }

  .section-nav {
    display: flex;
    gap: 8px;
    margin: 0 -12px;
    overflow-x: auto;
    padding: 0 12px 2px;
    scrollbar-width: none;
  }

  .section-nav::-webkit-scrollbar {
    display: none;
  }

  .section-nav button {
    flex: 0 0 auto;
    min-height: 42px;
    min-width: max-content;
    padding: 9px 11px;
  }

  .section-nav button > span:last-child {
    display: none;
  }

  .logout {
    display: none;
  }

  .workspace {
    padding: 16px;
  }

  .topbar,
  .dashboard-grid,
  .work-panels {
    grid-template-columns: 1fr;
  }

  .topbar {
    gap: 12px;
  }

  .topbar h1 {
    font-size: 24px;
  }

  .topbar .primary-action {
    justify-self: start;
  }

  .metrics {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
    margin: 14px 0;
  }

  .metric {
    min-width: 0;
    padding: 10px;
  }

  .metric strong {
    font-size: 20px;
  }

  .metric span {
    display: block;
    overflow-wrap: anywhere;
  }

  .content-table {
    border-left: 0;
    border-radius: 0;
    border-right: 0;
    margin: 0 -16px;
  }

  .table-head {
    display: none;
  }

  .table-body {
    max-height: none;
    overflow: visible;
  }

  .row {
    grid-template-columns: 1fr;
    align-items: start;
    gap: 8px;
    min-height: 0;
    padding: 14px 16px;
  }

  .tools {
    flex-direction: column;
  }

  .tools select {
    max-width: none;
  }

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

@media (max-width: 640px) {
  body {
    background: #fff;
  }

  .login-shell {
    width: min(420px, calc(100vw - 24px));
  }

  .login-panel {
    padding: 22px;
  }

  .sidebar {
    border-bottom: 1px solid rgba(255, 255, 255, 0.12);
  }

  .brand strong {
    font-size: 16px;
  }

  .brand span {
    grid-column: 1 / -1;
  }

  .brand em {
    grid-column: 1 / -1;
  }

  .workspace {
    padding: 14px;
  }

  .topbar {
    align-items: stretch;
  }

  .topbar p {
    font-size: 13px;
  }

  .search-box input {
    min-height: 44px;
  }

  .topbar .primary-action,
  .form-actions .primary-action,
  .form-actions .open-btn {
    width: 100%;
  }

  .metrics {
    display: flex;
    gap: 8px;
    margin: 12px -14px;
    overflow-x: auto;
    padding: 0 14px 2px;
    scroll-snap-type: x proximity;
    scrollbar-width: none;
  }

  .metrics::-webkit-scrollbar {
    display: none;
  }

  .metric {
    flex: 0 0 138px;
    scroll-snap-align: start;
  }

  .tools {
    gap: 10px;
  }

  .segmented {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 7px;
  }

  .segmented button,
  .tools select {
    min-height: 42px;
  }

  .content-table {
    margin: 0 -14px;
    border-top: 1px solid var(--line);
  }

  .row {
    position: relative;
    background: #fff;
    border-top: 8px solid var(--bg);
    padding: 14px;
  }

  .row:first-child {
    border-top-width: 0;
  }

  .title-cell strong,
  .field-muted,
  .cell-text,
  .title-cell small {
    white-space: normal;
    overflow: visible;
    text-overflow: clip;
  }

  .open-btn {
    width: 100%;
    min-height: 40px;
  }

  .studio-dashboard {
    gap: 12px;
    padding: 12px;
  }

  .dashboard-grid {
    gap: 8px;
  }

  .dashboard-card {
    grid-template-columns: auto 1fr auto;
    align-items: center;
    min-height: 74px;
    padding: 12px;
  }

  .dashboard-card small {
    grid-column: 2 / -1;
  }

  .dashboard-card strong {
    font-size: 24px;
  }

  .card-icon {
    grid-row: 1 / 3;
  }

  .work-panels {
    gap: 10px;
  }

  .panel-title {
    padding: 10px;
  }

  .mini-row {
    align-items: start;
    padding: 12px 10px;
  }

  .mini-row strong,
  .mini-row small {
    white-space: normal;
  }

  .mini-row b {
    white-space: normal;
    text-align: right;
  }

  .drawer-backdrop.open {
    z-index: 4;
  }

  .drawer {
    inset: auto 0 0 0;
    z-index: 5;
    width: 100vw;
    height: min(92vh, 720px);
    border-radius: 14px 14px 0 0;
    padding: 16px 14px 22px;
    transform: translateY(105%);
  }

  .drawer.open {
    transform: translateY(0);
  }

  .drawer-close {
    float: none;
    width: 100%;
    min-height: 40px;
    margin-bottom: 10px;
  }

  .drawer h2 {
    margin: 4px 0;
    font-size: 22px;
  }

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

  .drawer-actions .primary-action,
  .drawer-actions .danger-action {
    width: 100%;
    min-height: 42px;
  }

  .field,
  .note,
  .file-item {
    overflow-wrap: anywhere;
  }

  .file-item strong,
  .file-item small {
    white-space: normal;
  }

  .link-edit-head {
    display: none;
  }

  .link-edit-row {
    grid-template-columns: 1fr;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 8px;
  }
}

@media (max-width: 380px) {
  .workspace {
    padding: 12px;
  }

  .metrics {
    margin-left: -12px;
    margin-right: -12px;
    padding-left: 12px;
    padding-right: 12px;
  }

  .content-table {
    margin-left: -12px;
    margin-right: -12px;
  }

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