:root {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --ink: #171b20;
  --muted: #647181;
  --line: #d8dde5;
  --blue: #1769e8;
  --green: #16835d;
  --red: #c93f3f;
  --yellow: #d9971c;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: Arial, Helvetica, sans-serif;
  color: var(--ink);
  background: var(--bg);
}
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; }
.topbar {
  height: 72px;
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 0 28px;
  border-bottom: 1px solid var(--line);
  background: white;
  position: sticky;
  top: 0;
  z-index: 2;
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 250px; }
.mark { width: 40px; height: 40px; border-radius: 8px; display: grid; place-items: center; background: var(--ink); color: white; font-weight: 800; }
.brand small, .muted { color: var(--muted); }
.nav { display: flex; gap: 6px; flex-wrap: wrap; }
.nav a {
  padding: 10px 12px;
  border-radius: 8px;
  color: var(--muted);
}
.nav a.active, .nav a:hover { background: var(--ink); color: white; }
.logout { margin-left: auto; }
.wrap { width: min(1180px, calc(100% - 42px)); margin: 26px auto; }
.hero, .panel, .metric, .login-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}
.hero { padding: 22px; display: flex; justify-content: space-between; gap: 16px; align-items: center; margin-bottom: 16px; }
h1, h2, p { margin: 0; }
h1 { font-size: 28px; }
h2 { font-size: 18px; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.actions.vertical { align-items: flex-start; flex-direction: column; }
.btn {
  border: 0;
  border-radius: 8px;
  padding: 10px 14px;
  background: var(--blue);
  color: white;
  cursor: pointer;
}
.btn.secondary { background: white; color: var(--ink); border: 1px solid var(--line); }
.btn.danger { background: var(--red); }
.grid4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 14px; }
.metric { padding: 16px; border-top: 4px solid var(--blue); }
.metric strong { display: block; font-size: 30px; margin-top: 8px; }
.panel { padding: 16px; margin-bottom: 14px; }
.panel-head { display: flex; justify-content: space-between; gap: 12px; align-items: center; margin-bottom: 12px; }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { text-align: left; border-bottom: 1px solid var(--line); padding: 10px 8px; vertical-align: top; }
.table th { color: var(--muted); font-size: 13px; }
.compact-table th, .compact-table td { padding: 8px; }
.sync-summary { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; margin-bottom: 12px; }
.sync-summary > div { border: 1px solid var(--line); border-radius: 8px; padding: 12px; background: #f8fafc; }
.sync-summary strong { display: block; font-size: 18px; margin: 4px 0; }
.sync-summary small { display: block; color: var(--muted); overflow-wrap: anywhere; }
.badge { display: inline-block; padding: 5px 8px; border-radius: 999px; background: #e9eef7; color: var(--ink); font-size: 12px; }
.badge.pending { background: #fff1cd; }
.badge.in_progress { background: #dcecff; }
.badge.done { background: #dff4e9; }
.badge.late { background: #ffe2e2; }
.badge.active { background: #dff4e9; }
.badge.owing { background: #fff1cd; color: #6f4700; }
.badge.inactive { background: #eceff3; color: #6b7280; }
.active-filter { border-color: var(--blue); color: var(--blue); }
.tag-filters { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.tag-filters.left { justify-content: flex-start; }
.filter-tag,
.status-tag {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 26px;
  border-radius: 999px;
  border: 1px solid transparent;
  padding: 5px 10px;
  font-size: 13px;
  line-height: 1;
  white-space: nowrap;
}
.filter-tag strong { font-size: 12px; }
.filter-tag.all { background: #eef2f7; color: #293241; }
.filter-tag.active,
.status-tag.active { background: #dff4e9; color: #146c47; }
.filter-tag.owing,
.status-tag.owing { background: #fff1cd; color: #765100; }
.filter-tag.inactive,
.status-tag.inactive { background: #eceff3; color: #5f6875; }
.filter-tag.selected { border-color: currentColor; box-shadow: inset 0 0 0 1px currentColor; }
.status-tag { font-weight: 700; }
.debt-note {
  display: block;
  margin-top: 4px;
  color: #765100;
  font-size: 12px;
}
.small-note {
  display: block;
  margin-top: 4px;
  font-size: 12px;
}
.quick-filters { margin-bottom: 12px; }
.inline-form { margin-bottom: 6px; }
.mini-link {
  color: var(--blue);
  font-size: 12px;
  font-weight: 700;
}
.import-note { margin-top: 10px; font-size: 13px; }
.task-list { display: grid; gap: 12px; }
.task-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  overflow: hidden;
}
.task-main {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 14px;
  border-bottom: 1px solid var(--line);
}
.task-title { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 5px; }
.task-meta { display: grid; grid-template-columns: repeat(3, minmax(90px, 1fr)); gap: 12px; min-width: 330px; font-size: 13px; }
.doc-checklist { display: grid; }
.doc-row {
  display: grid;
  grid-template-columns: 28px 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
}
.doc-row:last-child { border-bottom: 0; }
.doc-check {
  width: 22px;
  height: 22px;
  border-radius: 999px;
  display: grid;
  place-items: center;
  font-weight: 800;
  background: #fff1cd;
  color: #765100;
}
.doc-check.done { background: #dff4e9; color: #146c47; }
.empty-state { padding: 16px; color: var(--muted); }
.form-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.form-grid.compact { margin-bottom: 12px; align-items: end; }
.form-grid .span-2 { grid-column: span 2; }
.rule-form { grid-template-columns: repeat(4, minmax(0, 1fr)); align-items: end; }
.rule-checks { display: grid; gap: 8px; align-self: end; }
.rule-due { display: grid; gap: 8px; min-width: 160px; }
label { display: grid; gap: 6px; color: var(--muted); font-size: 13px; }
input, select, textarea {
  min-width: 0;
  width: 100%;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  color: var(--ink);
}
textarea { min-height: 42px; resize: vertical; }
.notice { padding: 12px 14px; border-radius: 8px; background: #e7f5ef; color: var(--green); margin-bottom: 14px; }
.notice.warning { background: #fff1cd; color: #765100; }
.notice.error-box { background: #ffe2e2; color: var(--red); }
.login-page { min-height: 100vh; display: grid; place-items: center; background: linear-gradient(135deg, #111820, #1769e8); padding: 24px; }
.login-card { width: min(420px, 100%); padding: 26px; }
.login-card h1 { margin-bottom: 8px; }
.login-card form { display: grid; gap: 14px; margin-top: 20px; }
.version-note { margin-top: 8px; color: var(--muted); font-size: 12px; }
.error { color: var(--red); margin-top: 10px; }
.tree-path { font-size: 13px; color: var(--muted); word-break: break-word; }
.check-row { display: flex; gap: 10px; align-items: center; }
.check-row input { width: auto; }
.folder-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.folder-card {
  display: grid;
  grid-template-columns: 36px 1fr;
  gap: 10px;
  min-height: 96px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}
.folder-card.selected { border-color: var(--blue); box-shadow: inset 0 0 0 1px var(--blue); }
.folder-card strong, .folder-card span { display: block; }
.folder-card .badge { display: inline-block; margin-top: 8px; }
.folder-icon {
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: #e9eef7;
  color: var(--blue);
  font-weight: 800;
}
.drive-groups { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.drive-groups > div { display: flex; flex-wrap: wrap; gap: 8px; align-content: flex-start; }
.drive-chip {
  min-width: 170px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
}
.drive-chip strong, .drive-chip span { display: block; }
.drive-chip span { color: var(--muted); font-size: 12px; margin-top: 3px; }
.drive-chip.selected { border-color: var(--blue); color: var(--blue); }
.drive-tree { display: grid; gap: 10px; }
.tree-root { font-weight: 800; color: var(--blue); }
.tree-department {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  overflow: hidden;
}
.tree-department summary {
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 12px;
  background: #f8fafc;
}
.tree-docs { display: grid; gap: 10px; padding: 12px; }
.review-doc {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) minmax(360px, 1.4fr);
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
}
.review-doc.reviewed { border-color: #b8e4cd; background: #fbfffd; }
.review-doc strong, .review-doc span { display: block; }
.review-form { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; align-items: end; }
.viewer-shell { display: grid; gap: 14px; }
.viewer-meta {
  display: grid;
  gap: 4px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}
.viewer-frame {
  width: 100%;
  min-height: 72vh;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
}
.viewer-image-wrap {
  display: grid;
  place-items: center;
  min-height: 65vh;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
  overflow: auto;
}
.viewer-image {
  max-width: 100%;
  max-height: 78vh;
  object-fit: contain;
}
.viewer-fallback {
  display: grid;
  gap: 10px;
  justify-items: start;
}
@media (max-width: 900px) {
  .topbar, .hero, .panel-head { align-items: stretch; flex-direction: column; height: auto; }
  .logout { margin-left: 0; }
  .grid4, .form-grid { grid-template-columns: 1fr; }
  .form-grid .span-2 { grid-column: auto; }
  .folder-grid, .drive-groups { grid-template-columns: 1fr; }
  .review-doc, .review-form { grid-template-columns: 1fr; }
  .sync-summary { grid-template-columns: 1fr; }
  .task-main { flex-direction: column; }
  .task-meta { min-width: 0; grid-template-columns: 1fr; }
  .table { display: block; overflow-x: auto; }
}


.drive-dropzone {
  align-items: center;
  border: 2px dashed #93a4bd;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 8px;
  justify-content: center;
  min-height: 150px;
  padding: 22px;
  text-align: center;
  transition: background .15s ease, border-color .15s ease, box-shadow .15s ease;
}

.drive-dropzone input[type="file"] {
  height: 1px;
  opacity: 0;
  overflow: hidden;
  position: absolute;
  width: 1px;
}

.drive-dropzone .dropzone-icon {
  align-items: center;
  background: #e8eef8;
  border-radius: 999px;
  color: #2563eb;
  display: inline-flex;
  font-size: 28px;
  font-weight: 700;
  height: 46px;
  justify-content: center;
  line-height: 1;
  width: 46px;
}

.drive-dropzone small {
  color: #52627a;
}

.drive-dropzone.dragging {
  background: #eff6ff;
  border-color: #2563eb;
  box-shadow: 0 0 0 4px rgba(37, 99, 235, .12);
}

.drive-dropzone.has-file {
  background: #ecfdf3;
  border-color: #16a34a;
}

.drive-dropzone.has-file .dropzone-icon {
  background: #dcfce7;
  color: #15803d;
}
