/* ─────────────────────────────────────────────────────────
   คลังไฟล์โรงเรียน — สไตล์หลัก
   ───────────────────────────────────────────────────────── */

:root {
  --ink:        #1b2a2e;
  --ink-soft:   #56676b;
  --ink-faint:  #8b9a9d;
  --paper:      #f1f4f1;
  --surface:    #ffffff;
  --accent:     #14665a;
  --accent-dk:  #0e4c43;
  --accent-sf:  #e2eeea;
  --gold:       #9a6a14;
  --gold-sf:    #f7efdc;
  --danger:     #a4342b;
  --danger-sf:  #f8e7e5;
  --line:       #d7ded9;
  --line-soft:  #e8ede9;

  --radius:     6px;
  --radius-lg:  10px;
  --rail-w:     264px;
  --topbar-h:   60px;

  --shadow-lift: 0 8px 28px rgba(27, 42, 46, .16);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  background: var(--paper);
  color: var(--ink);
  font-family: 'Sarabun', system-ui, -apple-system, sans-serif;
  font-size: 15px;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3,
.btn, .topbar, .rail, .crumbs, .toolbar {
  font-family: 'IBM Plex Sans Thai', system-ui, sans-serif;
}

a { color: var(--accent); }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 3px;
}

/* ── ปุ่ม ───────────────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 8px 15px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  font-family: inherit;
  font-size: 14px;
  font-weight: 500;
  line-height: 1.4;
  cursor: pointer;
  transition: background .12s ease, border-color .12s ease;
}
.btn:hover:not(:disabled) { background: var(--line-soft); }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.btn--primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.btn--primary:hover:not(:disabled) { background: var(--accent-dk); border-color: var(--accent-dk); }

.btn--gold {
  background: var(--gold-sf);
  border-color: #e4d3ac;
  color: var(--gold);
}
.btn--gold:hover:not(:disabled) { background: #f0e3c6; }

.btn--danger {
  background: var(--danger-sf);
  border-color: #eccbc7;
  color: var(--danger);
}
.btn--danger:hover:not(:disabled) { background: #f3d9d5; }

.btn--quiet {
  border-color: transparent;
  background: transparent;
  color: var(--ink-soft);
  text-decoration: none;
}
.btn--quiet:hover { background: var(--line-soft); color: var(--ink); }

.btn--block { width: 100%; justify-content: center; padding: 11px; font-size: 15px; }

.iconbtn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border: 0;
  border-radius: var(--radius);
  background: transparent;
  color: var(--ink);
  cursor: pointer;
}
.iconbtn:hover { background: var(--line-soft); }

/* ── หน้าเข้าสู่ระบบ ─────────────────────────────────────── */

.signin-page {
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(ellipse at 20% 0%, #e4ede9 0%, transparent 55%),
    var(--paper);
}

.signin { width: 100%; max-width: 400px; }

.signin__brand { text-align: center; margin-bottom: 26px; }
.signin__brand .mark { color: var(--accent); }
.signin__brand h1 {
  margin: 10px 0 4px;
  font-size: 25px;
  font-weight: 600;
  letter-spacing: -.01em;
}
.signin__brand p {
  margin: 0;
  color: var(--ink-soft);
  font-size: 13.5px;
  line-height: 1.5;
}

.signin__form {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 26px 24px;
}

.signin__hint {
  margin: 16px 0 0;
  color: var(--ink-soft);
  font-size: 12.5px;
  line-height: 1.6;
}

.field { display: block; margin-bottom: 16px; }
.field > span {
  display: block;
  margin-bottom: 6px;
  font-family: 'IBM Plex Sans Thai', sans-serif;
  font-size: 13.5px;
  font-weight: 500;
}
.field input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  font-family: inherit;
  font-size: 15px;
}
.field input:focus {
  border-color: var(--accent);
  outline: none;
  box-shadow: 0 0 0 3px var(--accent-sf);
}

.alert {
  margin: 0 0 16px;
  padding: 10px 13px;
  border: 1px solid #eccbc7;
  border-left: 3px solid var(--danger);
  border-radius: var(--radius);
  background: var(--danger-sf);
  color: var(--danger);
  font-size: 14px;
}

/* ── แถบบน ──────────────────────────────────────────────── */

.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  gap: 14px;
  height: var(--topbar-h);
  padding: 0 18px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.topbar__menu { display: none; }

.topbar__brand strong {
  font-size: 16.5px;
  font-weight: 600;
  white-space: nowrap;
}

.topbar__search { flex: 1; max-width: 420px; margin-left: 8px; }
.topbar__search input {
  width: 100%;
  padding: 8px 13px;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: var(--paper);
  font-family: inherit;
  font-size: 14px;
  color: var(--ink);
}
.topbar__search input:focus {
  border-color: var(--accent);
  background: var(--surface);
  outline: none;
}

.topbar__user {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-left: auto;
}
.topbar__name { color: var(--ink-soft); font-size: 14px; }

/* ── โครงหน้า ───────────────────────────────────────────── */

.shell {
  display: grid;
  grid-template-columns: var(--rail-w) 1fr;
  min-height: calc(100vh - var(--topbar-h));
}

/* ── แถบซ้าย ────────────────────────────────────────────── */

.rail {
  padding: 20px 14px;
  border-right: 1px solid var(--line);
  background: var(--surface);
}

.rail__title {
  margin: 0 0 10px 8px;
  color: var(--ink-faint);
  font-size: 12.5px;
  font-weight: 600;
}
.rail__title--spaced { margin-top: 26px; }

.rail__list { margin: 0; padding: 0; list-style: none; }

.rail__item {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  padding: 9px 10px;
  border: 0;
  border-radius: var(--radius);
  background: transparent;
  color: var(--ink);
  font-family: inherit;
  font-size: 14.5px;
  text-align: left;
  cursor: pointer;
}
.rail__item:hover { background: var(--line-soft); }
.rail__item[aria-current="true"] {
  background: var(--accent-sf);
  color: var(--accent-dk);
  font-weight: 600;
}
.rail__item span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.rail__loading { padding: 9px 10px; color: var(--ink-faint); font-size: 14px; }

.rail__link {
  padding: 8px 10px;
  border: 0;
  background: none;
  color: var(--accent);
  font-family: inherit;
  font-size: 14px;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.rail__scrim { display: none; }

/* ── พื้นที่หลัก ────────────────────────────────────────── */

.pane {
  position: relative;
  padding: 26px 30px 60px;
  min-width: 0;
}

/* ตำแหน่งปัจจุบัน — ส่วนที่เน้นที่สุดของหน้า */
.place { margin-bottom: 20px; }

.crumbs {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px;
  min-height: 20px;
  margin-bottom: 4px;
  font-size: 13px;
  color: var(--ink-soft);
}
.crumbs button {
  padding: 2px 4px;
  border: 0;
  background: none;
  color: var(--ink-soft);
  font-family: inherit;
  font-size: 13px;
  cursor: pointer;
  border-radius: 3px;
}
.crumbs button:hover { color: var(--accent); background: var(--accent-sf); }
.crumbs .sep { color: var(--ink-faint); }

.place__name {
  margin: 0;
  font-size: 30px;
  font-weight: 600;
  letter-spacing: -.02em;
  line-height: 1.25;
  overflow-wrap: anywhere;
}

.place__meta {
  margin: 5px 0 0;
  color: var(--ink-soft);
  font-size: 13.5px;
}

/* ── แถบเครื่องมือ ──────────────────────────────────────── */

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 12px 0;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  margin-bottom: 4px;
}
.toolbar__gap { flex: 1; }
.toolbar__count {
  color: var(--accent-dk);
  font-size: 13.5px;
  font-weight: 600;
}

/* ── รายการไฟล์ ─────────────────────────────────────────── */

.listing { padding-top: 6px; }

.row {
  display: grid;
  grid-template-columns: 26px 40px 1fr 108px 168px;
  align-items: center;
  gap: 12px;
  padding: 9px 8px;
  border-bottom: 1px solid var(--line-soft);
  border-radius: var(--radius);
  cursor: default;
}
.row:hover { background: var(--surface); }
.row.is-selected { background: var(--accent-sf); }

.row__check { width: 17px; height: 17px; accent-color: var(--accent); cursor: pointer; }

.row__icon {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: var(--radius);
  background: var(--line-soft);
  color: var(--ink-soft);
  overflow: hidden;
}
.row__icon img { width: 100%; height: 100%; object-fit: cover; }
.row__icon--dir { background: var(--accent-sf); color: var(--accent); }

.row__name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.row__name button {
  border: 0;
  background: none;
  padding: 0;
  color: inherit;
  font-family: inherit;
  font-size: 15px;
  cursor: pointer;
  text-align: left;
}
.row__name button:hover { color: var(--accent); text-decoration: underline; text-underline-offset: 3px; }
.row--dir .row__name button { font-weight: 500; }

.row__size, .row__time {
  color: var(--ink-soft);
  font-size: 13px;
  white-space: nowrap;
}

.row__head {
  border-bottom: 1px solid var(--line);
  color: var(--ink-faint);
  font-family: 'IBM Plex Sans Thai', sans-serif;
  font-size: 12.5px;
  font-weight: 600;
}
.row__head:hover { background: transparent; }
.row__head button {
  border: 0;
  background: none;
  padding: 0;
  color: inherit;
  font-family: inherit;
  font-size: inherit;
  font-weight: inherit;
  cursor: pointer;
  text-align: left;
}
.row__head button:hover { color: var(--accent); }

.empty {
  padding: 44px 10px;
  color: var(--ink-soft);
  text-align: center;
  font-size: 14.5px;
}

/* ── ความคืบหน้าการอัปโหลด ─────────────────────────────── */

.uploads {
  margin: 14px 0;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--surface);
  overflow: hidden;
}
.up {
  display: grid;
  grid-template-columns: 1fr 76px;
  gap: 12px;
  align-items: center;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line-soft);
  font-size: 13.5px;
}
.up:last-child { border-bottom: 0; }
.up__name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.up__bar { height: 4px; border-radius: 2px; background: var(--line-soft); overflow: hidden; margin-top: 5px; }
.up__fill { height: 100%; width: 0; background: var(--accent); transition: width .15s linear; }
.up__state { text-align: right; color: var(--ink-soft); font-size: 12.5px; }
.up.is-done .up__state { color: var(--accent); }
.up.is-fail .up__state { color: var(--danger); }
.up.is-fail .up__fill { background: var(--danger); }

/* ── พื้นที่วางไฟล์ ─────────────────────────────────────── */

.dropzone {
  position: absolute;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  background: rgba(226, 238, 234, .93);
}
.dropzone__inner {
  padding: 26px 40px;
  border: 2px dashed var(--accent);
  border-radius: var(--radius-lg);
  color: var(--accent-dk);
  font-family: 'IBM Plex Sans Thai', sans-serif;
  font-size: 18px;
  font-weight: 600;
}

/* ── แจ้งเตือน ──────────────────────────────────────────── */

.toast {
  position: fixed;
  left: 50%;
  bottom: 26px;
  z-index: 90;
  transform: translateX(-50%);
  max-width: min(90vw, 460px);
  padding: 11px 18px;
  border-radius: var(--radius);
  background: var(--ink);
  color: #fff;
  font-size: 14px;
  box-shadow: var(--shadow-lift);
}
.toast.is-error { background: var(--danger); }

/* ── กล่องโต้ตอบ ────────────────────────────────────────── */

.modal {
  width: min(94vw, 460px);
  padding: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow-lift);
}
.modal::backdrop { background: rgba(27, 42, 46, .45); }

.modal__body { padding: 22px 24px; }

.modal__title {
  margin: 0 0 14px;
  font-size: 19px;
  font-weight: 600;
}

.modal__content { font-size: 14.5px; }
.modal__content p { margin: 0 0 12px; }
.modal__content .field:last-of-type { margin-bottom: 4px; }

.modal__actions {
  display: flex;
  flex-direction: row-reverse;
  justify-content: flex-start;
  gap: 8px;
  margin-top: 20px;
}

.linkbox {
  display: flex;
  gap: 6px;
  margin-bottom: 10px;
}
.linkbox input {
  flex: 1;
  min-width: 0;
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--paper);
  font-family: inherit;
  font-size: 13px;
  color: var(--ink);
}

.linklist { margin: 0; padding: 0; list-style: none; max-height: 46vh; overflow-y: auto; }
.linklist li {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid var(--line-soft);
}
.linklist strong { display: block; font-weight: 500; font-size: 14px; }
.linklist small { color: var(--ink-soft); font-size: 12.5px; word-break: break-all; }

/* ── จอเล็ก ─────────────────────────────────────────────── */

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

  .topbar__menu { display: inline-flex; }
  .topbar__brand { display: none; }
  .topbar__name { display: none; }

  .rail {
    position: fixed;
    top: var(--topbar-h);
    bottom: 0;
    right: auto;
    left: 0;
    z-index: 50;
    width: var(--rail-w);
    transform: translateX(-100%);
    transition: transform .2s ease;
    overflow-y: auto;
  }
  .rail.is-open { transform: translateX(0); }

  .rail__scrim {
    display: block;
    position: fixed;
    inset: var(--topbar-h) 0 0;
    z-index: 45;
    background: rgba(27, 42, 46, .4);
  }

  .pane { padding: 20px 16px 60px; }

  .place__name { font-size: 23px; }

  .row {
    grid-template-columns: 24px 38px 1fr;
    row-gap: 2px;
  }
  .row__size, .row__time { display: none; }
  .row__head { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
