:root {
  --bg: #08111f;
  --panel: #101c2d;
  --panel-2: #14253a;
  --text: #f3f7fc;
  --muted: #a9b7ca;
  --line: rgba(255, 255, 255, .14);
  --accent: #f7c64f;
  --accent-2: #58c7d9;
  --danger: #e35d6a;
  --shadow: rgba(0, 0, 0, .3);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: Sarabun, system-ui, sans-serif;
  background:
    linear-gradient(145deg, rgba(88, 199, 217, .16), transparent 35%),
    linear-gradient(210deg, rgba(247, 198, 79, .12), transparent 32%),
    var(--bg);
  color: var(--text);
}

button, input, select {
  font: inherit;
}

.shell {
  width: min(1200px, calc(100% - 28px));
  margin: 0 auto;
  padding: 18px 0 60px;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 3;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 0;
  background: rgba(8, 17, 31, .9);
  backdrop-filter: blur(12px);
}

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

.logo {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border-radius: 8px;
  background: var(--accent);
  color: #1d2330;
  font-weight: 800;
}

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

h1 {
  margin-bottom: 2px;
  font-size: clamp(22px, 3vw, 30px);
}

.brand p, .dialog-head p, .hint, .status {
  color: var(--muted);
}

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

.actions.end {
  justify-content: flex-end;
  margin-top: 18px;
}

.button {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 14px;
  background: #1b304c;
  color: var(--text);
  font-weight: 700;
  cursor: pointer;
}

.button.primary {
  border-color: transparent;
  background: var(--accent);
  color: #1b1607;
}

.button.danger {
  border-color: transparent;
  background: var(--danger);
  color: white;
}

.filters {
  display: grid;
  grid-template-columns: 1fr 170px;
  gap: 10px;
  margin: 14px 0;
}

input, select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #0b1728;
  color: var(--text);
}

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

.card {
  display: flex;
  min-height: 210px;
  flex-direction: column;
  gap: 12px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: linear-gradient(180deg, var(--panel-2), var(--panel));
  box-shadow: 0 18px 42px var(--shadow);
}

.card h2 { margin-bottom: 0; }

.description {
  min-height: 48px;
  color: #d8e3ef;
  line-height: 1.55;
}

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

.chip {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 5px 9px;
  background: #09182a;
  color: #cde7ff;
  font-size: 13px;
}

.card .button {
  margin-top: auto;
}

.dialog {
  width: min(980px, calc(100% - 24px));
  max-height: 90vh;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  background: var(--bg);
  color: var(--text);
  box-shadow: 0 24px 80px rgba(0, 0, 0, .55);
}

.dialog::backdrop {
  background: rgba(0, 0, 0, .72);
}

.dialog.wide {
  width: min(1120px, calc(100% - 24px));
}

.dialog-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 12px;
  margin-bottom: 14px;
}

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

label {
  display: grid;
  gap: 6px;
  color: #d4deec;
}

.editor-section {
  margin-top: 18px;
}

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

.rows, .doc-list {
  display: grid;
  gap: 9px;
}

.edit-row, .doc-row {
  display: grid;
  grid-template-columns: 1fr 1.4fr auto;
  align-items: center;
  gap: 8px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #0b1728;
}

.doc-row {
  grid-template-columns: 1fr auto;
}

.doc-row strong {
  display: block;
}

.doc-path, .doc-meta {
  overflow-wrap: anywhere;
  color: var(--muted);
  font-size: 13px;
}

.file-control {
  display: grid;
  min-height: 48px;
  align-content: center;
  border: 1px dashed var(--line);
  border-radius: 8px;
  padding: 9px 12px;
  background: #081320;
  color: #d4deec;
  cursor: pointer;
}

.file-control span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-control input {
  display: none;
}

.viewer-frame {
  width: 100%;
  height: 72vh;
  border: 0;
  border-radius: 8px;
  background: white;
}

.viewer-image {
  display: block;
  max-width: 100%;
  max-height: 72vh;
  margin: 0 auto;
  border-radius: 8px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 20px;
  display: none;
  max-width: min(520px, calc(100% - 28px));
  transform: translateX(-50%);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px 16px;
  background: #111827;
  color: white;
  box-shadow: 0 12px 30px var(--shadow);
}

.pin-dialog {
  width: min(380px, calc(100% - 24px));
}

.pin-panel {
  display: grid;
  gap: 12px;
}

.pin-input {
  text-align: center;
  font-size: 28px;
  font-weight: 800;
  letter-spacing: 6px;
}

.pin-pad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.pin-pad .button {
  min-height: 54px;
  font-size: 20px;
}

@media (max-width: 900px) {
  .topbar, .dialog-head {
    align-items: stretch;
    flex-direction: column;
  }

  .filters, .grid, .form-grid, .edit-row, .doc-row {
    grid-template-columns: 1fr;
  }
}
