:root {
  --bg: #0f172a;
  --bg-soft: #16213a;
  --panel: #1e293b;
  --border: #334155;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --green: #10b981;
  --red: #ef4444;
  --amber: #f59e0b;
  --radius: 12px;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
}

a { color: #93c5fd; text-decoration: none; }
a:hover { text-decoration: underline; }

h1 { font-size: 22px; margin: 0 0 6px; font-weight: 650; }
h2 { font-size: 17px; margin: 0 0 12px; }

.muted { color: var(--muted); }
.small { font-size: 13px; }
.sep { color: var(--border); margin: 0 6px; }

/* topbar */
.topbar {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 12px 28px;
  background: var(--bg-soft);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 50;
}

.brand { font-weight: 700; letter-spacing: .3px; color: var(--text); font-size: 15px; }

.mainnav { display: flex; gap: 4px; flex: 1; }
.mainnav a {
  padding: 6px 12px;
  border-radius: 8px;
  color: var(--muted);
  font-size: 14px;
}
.mainnav a:hover { background: #1e293b; text-decoration: none; color: var(--text); }
.mainnav a.active { background: #1e293b; color: var(--text); }

.userbox { display: flex; align-items: center; gap: 10px; font-size: 14px; }
.username { color: var(--text); }
.rolebadge {
  font-size: 12px;
  padding: 3px 9px;
  border-radius: 999px;
  background: #0b3b5c;
  color: #7dd3fc;
}

/* layout */
.container { max-width: 1180px; margin: 0 auto; padding: 28px; }

.page-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 24px;
  margin-bottom: 20px;
}

.breadcrumbs { font-size: 13px; color: var(--muted); margin-bottom: 14px; }

.stats { display: flex; gap: 10px; }
.stat {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 16px;
  min-width: 92px;
  text-align: center;
}
.stat-value { display: block; font-size: 20px; font-weight: 650; }
.stat-label { font-size: 12px; color: var(--muted); }

/* cards */
.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 14px;
}
.card {
  display: block;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  color: var(--text);
  transition: border-color .15s, transform .15s;
}
.card:hover { border-color: var(--accent); text-decoration: none; transform: translateY(-1px); }
.card-title { font-weight: 600; margin-bottom: 6px; }
.card-footer { display: flex; gap: 8px; margin-top: 14px; flex-wrap: wrap; }

.pill {
  font-size: 12px;
  padding: 3px 10px;
  border-radius: 999px;
  background: #0f2742;
  color: #93c5fd;
  border: 1px solid #1e3a5f;
}

/* panels & forms */
.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 22px;
}
.panel > summary {
  display: inline-block;
  cursor: pointer;
  list-style: none;
  margin-bottom: 4px;
}
.panel > summary::-webkit-details-marker { display: none; }
.panel[open] > summary { margin-bottom: 16px; }
.panel:not([open]) { padding: 0; background: none; border: none; margin-bottom: 18px; }
.panel-title { margin-bottom: 14px; }

.grid-form {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}
.grid-form .span-2 { grid-column: 1 / -1; }

label { display: block; font-size: 13px; color: var(--muted); }
input[type="text"], input[type="email"], input[type="password"], select, textarea {
  width: 100%;
  margin-top: 5px;
  padding: 9px 12px;
  background: #0f1b2d;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font: inherit;
  font-size: 14px;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
}
textarea { resize: vertical; }

/* buttons */
.btn {
  display: inline-block;
  padding: 9px 16px;
  border-radius: 8px;
  border: 1px solid transparent;
  font: inherit;
  font-size: 14px;
  cursor: pointer;
  transition: background .15s, border-color .15s;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-ghost { background: transparent; border-color: var(--border); color: var(--text); }
.btn-ghost:hover { background: #0f1b2d; text-decoration: none; }
.btn-danger { background: transparent; border-color: #7f1d1d; color: #fca5a5; }
.btn-danger:hover { background: #7f1d1d; color: #fff; }
.btn-sm { padding: 5px 10px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* tables */
.table {
  width: 100%;
  border-collapse: collapse;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.table th, .table td {
  text-align: left;
  padding: 11px 14px;
  font-size: 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.table th { color: var(--muted); font-weight: 500; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.table tr:last-child td { border-bottom: none; }
.table tr:hover td { background: #17223a; }
.table .actions { display: flex; gap: 8px; align-items: center; }
.inline-form { display: flex; gap: 6px; }
.inline-form input { width: 150px; margin-top: 0; padding: 5px 10px; font-size: 13px; }

/* statuses */
.status {
  display: inline-block;
  font-size: 12px;
  padding: 3px 10px;
  border-radius: 999px;
  border: 1px solid transparent;
}
.status-draft, .status-uploaded { background: #1e293b; color: #94a3b8; border-color: var(--border); }
.status-processing { background: #3f2d0a; color: #fbbf24; border-color: #7c5a10; }
.status-ready, .status-analyzed, .status-converted { background: #052e22; color: #6ee7b7; border-color: #14532d; }
.status-error { background: #3f0f0f; color: #fca5a5; border-color: #7f1d1d; }

/* alerts */
.alert {
  padding: 11px 16px;
  border-radius: 8px;
  margin-bottom: 16px;
  font-size: 14px;
}
.alert-info { background: #0b2942; border: 1px solid #1e4a6f; color: #bae6fd; }
.alert-error { background: #3f0f0f; border: 1px solid #7f1d1d; color: #fecaca; }

/* empty */
.empty {
  text-align: center;
  padding: 56px 20px;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  color: var(--muted);
}

/* login */
.login-page { display: grid; place-items: center; }
.login-card {
  width: min(420px, 92vw);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 36px;
}
.login-card h1 { margin-bottom: 4px; }
.stack { display: grid; gap: 14px; margin-top: 24px; }

/* upload */
.upload-form { display: grid; gap: 14px; }
.dropzone {
  display: grid;
  place-items: center;
  text-align: center;
  padding: 36px 20px;
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  background: #0f1b2d;
  cursor: pointer;
  transition: border-color .15s, background .15s;
  color: var(--text);
}
.dropzone:hover, .dropzone.dragover { border-color: var(--accent); background: #12233a; }
.dropzone input[type="file"] { display: none; }
.dropzone-text { font-size: 14px; }
.upload-actions { display: flex; align-items: center; gap: 14px; }

/* sheet grid */
.sheet-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 14px;
}
.sheet-card {
  display: block;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  color: var(--text);
  transition: border-color .15s;
}
.sheet-card:hover { border-color: var(--accent); text-decoration: none; }
.sheet-thumb {
  aspect-ratio: 4 / 3;
  background: #0b1424;
  display: grid;
  place-items: center;
  overflow: hidden;
}
.sheet-thumb img { width: 100%; height: 100%; object-fit: contain; }
.sheet-meta { padding: 10px 12px; display: grid; gap: 2px; }
.sheet-no { font-weight: 600; font-size: 13px; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* viewer */
.viewer-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 10px 14px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 14px;
  flex-wrap: wrap;
}
.viewer-info { display: flex; align-items: baseline; gap: 12px; }
.viewer-actions { display: flex; align-items: center; gap: 8px; }
.zoom-value { font-size: 13px; color: var(--muted); min-width: 46px; text-align: center; }

.viewer {
  height: calc(100vh - 210px);
  min-height: 420px;
  overflow: hidden;
  background: #0b1424;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: grab;
  position: relative;
}
.viewer.dragging { cursor: grabbing; }
.viewer img {
  position: absolute;
  transform-origin: 0 0;
  user-select: none;
  max-width: none;
}

@media (max-width: 720px) {
  .container { padding: 18px; }
  .topbar { padding: 10px 16px; gap: 12px; flex-wrap: wrap; }
  .page-head { flex-direction: column; }
  .grid-form { grid-template-columns: 1fr; }
  .grid-form .span-2 { grid-column: auto; }
  .stats { width: 100%; }
}
