:root {
  color-scheme: light;
  --ink: #202521;
  --muted: #606a64;
  --border: #cbd3ce;
  --surface: #ffffff;
  --canvas: #eef1ef;
  --sidebar: #202521;
  --sidebar-muted: #aeb9b2;
  --green: #286b4a;
  --green-dark: #1f543a;
  --amber: #a86614;
  --red: #a23131;
  --focus: #1473e6;
  font-family: Inter, Aptos, "Segoe UI", Arial, sans-serif;
}

* { box-sizing: border-box; }
html { min-width: 320px; background: var(--canvas); }
body { margin: 0; color: var(--ink); background: var(--canvas); }
button, input, select { font: inherit; }
button, a, summary { -webkit-tap-highlight-color: transparent; }
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible, summary:focus-visible {
  outline: 3px solid rgb(20 115 230 / 28%);
  outline-offset: 2px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.eyebrow {
  margin: 0;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  line-height: 1.2;
  letter-spacing: 0;
  text-transform: uppercase;
}

.brand-mark {
  display: grid;
  width: 42px;
  height: 42px;
  flex: 0 0 42px;
  place-items: center;
  border: 1px solid rgb(255 255 255 / 24%);
  border-radius: 6px;
  background: #f5a623;
  color: #17201b;
  font-size: 12px;
  font-weight: 900;
}

.app-shell { display: grid; min-height: 100vh; grid-template-columns: 244px minmax(0, 1fr); }
body:not(.is-authenticated) .app-shell { display: none; }
body.is-authenticated .auth-screen { display: none; }

.sidebar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  height: 100vh;
  min-height: 560px;
  flex-direction: column;
  padding: 20px 14px 14px;
  background: var(--sidebar);
  color: #ffffff;
}

.brand { display: flex; align-items: center; gap: 11px; padding: 0 7px 22px; }
.brand div { display: grid; gap: 2px; min-width: 0; }
.brand strong { overflow: hidden; font-size: 15px; text-overflow: ellipsis; white-space: nowrap; }
.brand span:not(.brand-mark) { color: var(--sidebar-muted); font-size: 12px; }

.nav-list { display: grid; gap: 4px; }
.nav-group-label { padding: 10px 10px 5px; color: #849188; font-size: 10px; font-weight: 800; text-transform: uppercase; }
.nav-link {
  display: grid;
  width: 100%;
  min-height: 44px;
  grid-template-columns: 20px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border: 1px solid transparent;
  border-radius: 5px;
  background: transparent;
  color: #d9e0dc;
  text-align: left;
  cursor: pointer;
}
.nav-link svg, .topbar-actions svg, .search-control svg, .file-icon svg, .empty-state svg, .file-drop svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.nav-link:hover { background: rgb(255 255 255 / 7%); }
.nav-link.active { border-color: rgb(255 255 255 / 10%); background: #35403a; color: #ffffff; }
.nav-count { min-width: 25px; padding: 2px 6px; border-radius: 4px; background: rgb(255 255 255 / 10%); color: #d7dfda; font-size: 11px; text-align: center; }

.suite-switcher { margin-top: auto; padding-top: 18px; }
.suite-launcher { border-top: 1px solid rgb(255 255 255 / 11%); border-bottom: 1px solid rgb(255 255 255 / 11%); }
.suite-launcher summary { padding: 13px 9px; color: var(--sidebar-muted); font-size: 12px; font-weight: 700; cursor: pointer; }
.suite-links { display: grid; gap: 2px; padding: 0 0 9px; }
.suite-link { display: flex; align-items: center; gap: 8px; min-height: 34px; padding: 5px 9px; border-radius: 4px; color: #d9e0dc; font-size: 12px; text-decoration: none; }
.suite-link:hover, .suite-link.current { background: rgb(255 255 255 / 8%); color: #ffffff; }
.suite-site-code { display: grid; width: 29px; height: 22px; place-items: center; border: 1px solid rgb(255 255 255 / 18%); border-radius: 3px; font-size: 9px; font-weight: 900; }

.sidebar-status { display: grid; gap: 3px; padding: 15px 9px 4px; }
.sidebar-status .eyebrow { color: #839088; }
.sidebar-status strong { overflow: hidden; font-size: 13px; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-status > span:last-child { color: var(--sidebar-muted); font-size: 11px; }

.workspace { min-width: 0; padding: 0 28px 40px; }
.topbar { display: flex; min-height: 112px; align-items: center; justify-content: space-between; gap: 24px; border-bottom: 1px solid var(--border); }
.topbar h1 { margin: 5px 0 4px; font-size: 26px; line-height: 1.1; }
.context-line { margin: 0; color: var(--muted); font-size: 13px; }
.topbar-actions { display: flex; gap: 8px; }

.primary-button, .secondary-button, .danger-button, .icon-button, .row-action {
  display: inline-flex;
  min-height: 40px;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px 14px;
  border: 1px solid transparent;
  border-radius: 5px;
  font-weight: 750;
  line-height: 1;
  cursor: pointer;
}
.primary-button { border-color: var(--green-dark); background: var(--green); color: #ffffff; }
.primary-button:hover { background: var(--green-dark); }
.secondary-button { border-color: var(--border); background: #ffffff; color: var(--ink); }
.secondary-button:hover { background: #f4f6f4; }
.danger-button { border-color: #8f2929; background: var(--red); color: #ffffff; }
.icon-button { width: 38px; min-height: 38px; padding: 0; border-color: var(--border); background: transparent; color: var(--ink); font-size: 25px; }
button:disabled { opacity: .55; cursor: wait; }

.association-tabs { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); border-bottom: 1px solid var(--border); }
.association-tab { display: grid; min-height: 68px; gap: 3px; padding: 12px 18px; border: 0; border-bottom: 3px solid transparent; background: transparent; color: var(--muted); text-align: left; cursor: pointer; }
.association-tab span { color: var(--ink); font-size: 14px; font-weight: 800; }
.association-tab small { font-size: 11px; }
.association-tab:hover { background: rgb(255 255 255 / 48%); }
.association-tab.active { border-bottom-color: var(--green); background: #ffffff; }

.library-summary { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); margin: 20px 0; border: 1px solid var(--border); border-radius: 6px; background: var(--surface); }
.library-summary > div { display: grid; gap: 5px; min-width: 0; padding: 14px 17px; border-right: 1px solid var(--border); }
.library-summary > div:last-child { border-right: 0; }
.library-summary span { color: var(--muted); font-size: 11px; font-weight: 700; }
.library-summary strong { overflow: hidden; font-size: 17px; text-overflow: ellipsis; white-space: nowrap; }

.library-panel { border: 1px solid var(--border); border-radius: 6px; background: var(--surface); overflow: hidden; }
.library-heading { display: flex; align-items: end; justify-content: space-between; gap: 24px; padding: 20px; }
.library-heading h2 { margin: 4px 0 0; font-size: 20px; }
.library-tools { display: flex; gap: 8px; }
.search-control { display: flex; width: min(330px, 35vw); min-height: 40px; align-items: center; gap: 8px; padding: 0 11px; border: 1px solid var(--border); border-radius: 5px; background: #ffffff; }
.search-control svg { width: 17px; color: var(--muted); }
.search-control input { width: 100%; min-width: 0; border: 0; outline: 0; color: var(--ink); }
.sort-control select { min-height: 40px; padding: 0 32px 0 10px; border: 1px solid var(--border); border-radius: 5px; background: #ffffff; color: var(--ink); }

.breadcrumbs { display: flex; min-height: 44px; align-items: center; gap: 4px; padding: 6px 20px; border-top: 1px solid var(--border); border-bottom: 1px solid var(--border); background: #f6f8f6; overflow-x: auto; }
.breadcrumb-button { min-height: 30px; padding: 4px 7px; border: 0; border-radius: 4px; background: transparent; color: var(--green-dark); font-weight: 700; white-space: nowrap; cursor: pointer; }
.breadcrumb-button:hover { background: #e7ede9; }
.breadcrumb-separator { color: #95a099; }

.table-wrap { width: 100%; overflow-x: auto; }
.file-table { width: 100%; border-collapse: collapse; table-layout: fixed; }
.file-table th { padding: 10px 14px; border-bottom: 1px solid var(--border); color: var(--muted); font-size: 10px; text-align: left; text-transform: uppercase; }
.file-table th:first-child { width: 43%; padding-left: 20px; }
.file-table th:nth-child(2) { width: 18%; }
.file-table th:nth-child(3) { width: 17%; }
.file-table th:nth-child(4) { width: 10%; }
.file-table th:last-child { width: 12%; }
.file-table td { height: 62px; padding: 9px 14px; border-bottom: 1px solid #e1e6e3; color: var(--muted); font-size: 12px; vertical-align: middle; }
.file-table td:first-child { padding-left: 20px; color: var(--ink); }
.file-table tbody tr:hover { background: #f7f9f7; }
.file-table tbody tr:last-child td { border-bottom: 0; }
.file-name { display: flex; min-width: 0; align-items: center; gap: 11px; }
.file-icon { display: grid; width: 36px; height: 36px; flex: 0 0 36px; place-items: center; border-radius: 5px; background: #e8efea; color: var(--green-dark); }
.file-icon.folder { background: #f5ecd9; color: var(--amber); }
.file-name-button { min-width: 0; padding: 0; border: 0; background: none; color: inherit; font-weight: 750; overflow: hidden; text-align: left; text-overflow: ellipsis; white-space: nowrap; cursor: pointer; }
.file-name-button:hover { color: var(--green); text-decoration: underline; }
.file-metadata-mobile { display: none; color: var(--muted); font-size: 11px; font-weight: 500; }
.row-actions { display: flex; justify-content: flex-end; gap: 4px; }
.row-action { min-width: 34px; min-height: 34px; padding: 0 8px; border-color: var(--border); background: #ffffff; color: var(--ink); font-size: 11px; }
.row-action:hover { background: #edf2ee; }
.row-action svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.row-action.danger { color: var(--red); }

.empty-state, .loading-state { min-height: 270px; align-items: center; justify-content: center; text-align: center; }
.empty-state { display: flex; flex-direction: column; gap: 8px; color: var(--muted); }
.empty-state[hidden] { display: none; }
.empty-state svg { width: 42px; height: 42px; margin-bottom: 4px; color: #8c9891; }
.empty-state strong { color: var(--ink); }
.loading-state { display: flex; gap: 10px; color: var(--muted); }
.loading-state[hidden] { display: none; }
.spinner { width: 18px; height: 18px; border: 2px solid #cbd3ce; border-top-color: var(--green); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.library-dialog { width: min(620px, calc(100vw - 28px)); max-height: calc(100vh - 28px); padding: 0; border: 1px solid var(--border); border-radius: 7px; background: #ffffff; color: var(--ink); box-shadow: 0 24px 70px rgb(18 25 21 / 30%); }
.library-dialog::backdrop { background: rgb(18 25 21 / 55%); }
.library-dialog form { display: grid; gap: 18px; padding: 22px; overflow-y: auto; }
.library-dialog header { display: flex; align-items: start; justify-content: space-between; gap: 16px; padding-bottom: 14px; border-bottom: 1px solid var(--border); }
.library-dialog h2 { margin: 3px 0 0; font-size: 21px; }
.library-dialog label:not(.file-drop) { display: grid; gap: 7px; color: var(--muted); font-size: 12px; font-weight: 750; }
.library-dialog input:not([type="file"]), .library-dialog select { width: 100%; min-height: 42px; padding: 8px 10px; border: 1px solid var(--border); border-radius: 5px; color: var(--ink); }
.library-dialog footer { display: flex; justify-content: flex-end; gap: 8px; padding-top: 4px; }
.compact-dialog { width: min(470px, calc(100vw - 28px)); }
.dialog-path { margin: -4px 0 0; color: var(--muted); font-size: 12px; }
.form-notice { min-height: 18px; color: var(--muted); font-size: 12px; }
.form-notice[data-tone="error"] { color: var(--red); }
.file-drop { display: grid; min-height: 178px; place-items: center; align-content: center; gap: 7px; padding: 20px; border: 1px dashed #9eaaa2; border-radius: 6px; background: #f7f9f7; text-align: center; cursor: pointer; }
.file-drop:hover, .file-drop.dragging { border-color: var(--green); background: #eef5f0; }
.file-drop input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.file-drop svg { width: 30px; height: 30px; color: var(--green); }
.file-drop span { color: var(--muted); font-size: 11px; font-weight: 500; }
.selected-files { display: grid; gap: 5px; max-height: 145px; overflow-y: auto; }
.selected-file { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 7px 9px; border: 1px solid #e0e5e2; border-radius: 4px; font-size: 12px; }
.selected-file span:first-child { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.selected-file span:last-child { flex: 0 0 auto; color: var(--muted); }
.danger-dialog h2 { color: #7f2525; }
.danger-dialog p { margin: 0; color: var(--muted); line-height: 1.55; }

.toast { position: fixed; right: 20px; bottom: 20px; z-index: 200; max-width: min(380px, calc(100vw - 40px)); padding: 11px 14px; border: 1px solid #9db8a7; border-radius: 5px; background: #eef6f0; color: #1f5137; box-shadow: 0 8px 28px rgb(25 37 29 / 18%); font-size: 13px; font-weight: 700; opacity: 0; transform: translateY(8px); pointer-events: none; transition: opacity .18s, transform .18s; }
.toast.visible { opacity: 1; transform: translateY(0); }
.toast.error { border-color: #d2a5a5; background: #fbefef; color: #842828; }

body:not(.can-upload) .upload-only { display: none !important; }
body.can-upload .view-only-copy { display: none; }
body:not(.can-upload) .view-only-copy { display: inline; }
body:not(.can-manage) .manage-only { display: none !important; }

@media (max-width: 980px) {
  .app-shell { grid-template-columns: 204px minmax(0, 1fr); }
  .workspace { padding-inline: 20px; }
  .library-summary { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .library-summary > div:nth-child(2) { border-right: 0; }
  .library-summary > div:nth-child(-n+2) { border-bottom: 1px solid var(--border); }
  .file-table th:nth-child(2), .file-table td:nth-child(2) { display: none; }
  .file-table th:first-child { width: 50%; }
}

@media (max-width: 720px) {
  .app-shell { display: block; }
  .sidebar { position: static; height: auto; min-height: 0; padding: 12px; }
  .brand { padding: 0 2px 12px; }
  .brand-mark { width: 38px; height: 38px; flex-basis: 38px; }
  .nav-list { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .nav-group-label { display: none; }
  .nav-link { min-height: 42px; grid-template-columns: 18px minmax(0, 1fr); gap: 7px; padding: 7px 8px; }
  .nav-link .nav-count { display: none; }
  .nav-link svg { width: 17px; }
  .suite-switcher { margin: 0; padding-top: 10px; }
  .suite-launcher summary { padding-block: 10px; }
  .sidebar-status { display: none; }
  .workspace { padding: 0 12px 28px; }
  .topbar { min-height: 126px; align-items: start; padding: 18px 0; }
  .topbar h1 { font-size: 23px; }
  .context-line { max-width: 250px; }
  .topbar-actions { align-self: end; }
  .topbar-actions .secondary-button { width: 42px; padding: 0; font-size: 0; }
  .topbar-actions .secondary-button svg { width: 19px; }
  .association-tabs { margin-inline: -12px; }
  .association-tab { min-height: 56px; padding: 9px 12px; text-align: center; }
  .association-tab small { display: none; }
  .library-summary { margin-block: 14px; }
  .library-summary > div { padding: 11px 12px; }
  .library-summary strong { font-size: 14px; }
  .library-heading { display: grid; gap: 14px; padding: 16px 14px; }
  .library-tools { width: 100%; }
  .search-control { width: 100%; }
  .sort-control select { width: 70px; padding-inline: 7px 22px; font-size: 11px; }
  .breadcrumbs { padding-inline: 10px; }
  .file-table thead { display: none; }
  .file-table, .file-table tbody, .file-table tr, .file-table td { display: block; width: 100%; }
  .file-table tr { position: relative; min-height: 72px; border-bottom: 1px solid #e1e6e3; }
  .file-table td { display: none; height: auto; border: 0; }
  .file-table td:first-child { display: block; padding: 14px 96px 14px 13px; }
  .file-table td:last-child { position: absolute; top: 18px; right: 10px; display: block; padding: 0; }
  .file-icon { width: 38px; height: 38px; flex-basis: 38px; }
  .file-name { align-items: start; }
  .file-name-button { max-width: 100%; }
  .file-metadata-mobile { display: block; margin-top: 4px; }
  .row-action { min-width: 36px; padding-inline: 7px; }
  .row-action span { display: none; }
  .library-dialog form { padding: 18px; }
  .file-drop { min-height: 150px; }
}

@media (max-width: 430px) {
  .topbar { display: grid; gap: 14px; }
  .topbar-actions { width: 100%; align-self: auto; justify-content: flex-end; }
  .topbar-actions .primary-button { flex: 1; }
  .association-tab { padding-inline: 7px; }
  .association-tab span { font-size: 12px; }
  .library-summary span { font-size: 10px; }
  .library-dialog footer { display: grid; grid-template-columns: 1fr 1fr; }
}
