/* ===================== Tokens ===================== */
:root {
  --ink: #10161A;
  --panel: #1A2226;
  --panel-2: #212B30;
  --paper: #F6F1E4;
  --paper-dim: #EAE2CE;
  --brass: #B08D57;
  --brass-bright: #CBA86A;
  --verdigris: #4F7A72;
  --rust: #A64B3C;
  --ink-text: #E8E4D8;
  --ink-text-dim: #9CA8AC;
  --border: rgba(232, 228, 216, 0.1);
  --serif: "Fraunces", "Noto Sans Bengali", serif;
  --sans: "Inter", "Noto Sans Bengali", sans-serif;
  --radius: 10px;
  --shadow: 0 12px 32px rgba(0,0,0,0.35);
}

* { box-sizing: border-box; }

html {
  scroll-padding-top: env(safe-area-inset-top, 0px);
}

body {
  margin: 0;
  min-height: 100%;
  background: var(--ink);
  color: var(--ink-text);
  font-family: var(--sans);
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

.hidden { display: none !important; }

button {
  font-family: inherit;
  cursor: pointer;
}

input, textarea {
  font-family: inherit;
}

/* ===================== Login screen ===================== */
#login-screen {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background:
    radial-gradient(ellipse at 50% -10%, rgba(176,141,87,0.12), transparent 60%),
    var(--ink);
}

.login-card {
  width: 100%;
  max-width: 360px;
  text-align: center;
  padding: 40px 32px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow);
}

.dial {
  margin: 0 auto 18px;
  width: 72px;
  height: 72px;
}
.dial-ring { fill: none; stroke: var(--border); stroke-width: 1.5; }
.dial-hub { fill: var(--brass); }
.dial-needle { stroke: var(--brass-bright); stroke-width: 2.5; stroke-linecap: round; transform-origin: 60px 60px; }
.dial-tip { fill: var(--brass-bright); }

@keyframes dial-spin {
  0% { transform: rotate(0deg); }
  60% { transform: rotate(390deg); }
  100% { transform: rotate(360deg); }
}
.dial.spinning .dial-needle { animation: dial-spin 0.7s cubic-bezier(.2,.8,.2,1); }

.login-card h1 {
  font-family: var(--serif);
  font-weight: 500;
  font-size: 2rem;
  margin: 0 0 4px;
  letter-spacing: 0.01em;
}

.login-sub {
  color: var(--ink-text-dim);
  font-size: 0.92rem;
  margin: 0 0 28px;
}

#login-form { text-align: left; display: flex; flex-direction: column; gap: 16px; }

#login-form label { display: flex; flex-direction: column; gap: 6px; font-size: 0.85rem; color: var(--ink-text-dim); }

#login-form input {
  background: var(--ink);
  border: 1px solid var(--border);
  color: var(--ink-text);
  padding: 11px 13px;
  border-radius: 8px;
  font-size: 0.95rem;
  outline: none;
  transition: border-color 0.15s;
}
#login-form input:focus {
  border-color: var(--brass);
}

#login-btn {
  margin-top: 6px;
  background: var(--brass);
  color: #1A1206;
  border: none;
  padding: 12px;
  border-radius: 8px;
  font-weight: 600;
  font-size: 0.95rem;
  transition: background 0.15s;
}
#login-btn:hover { background: var(--brass-bright); }
#login-btn:disabled { opacity: 0.6; cursor: default; }
#login-btn:focus-visible, .tab:focus-visible, .save-btn:focus-visible, .ghost-btn:focus-visible, .dropzone:focus-visible, .item-btn:focus-visible {
  outline: 2px solid var(--brass-bright);
  outline-offset: 2px;
}

.login-error {
  min-height: 1.1em;
  color: var(--rust);
  font-size: 0.85rem;
  margin: 4px 0 0;
}

/* ===================== App shell ===================== */
#app { min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  padding-top: calc(14px + env(safe-area-inset-top, 0px));
  border-bottom: 1px solid var(--border);
  background: var(--panel);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--serif);
  font-size: 1.2rem;
  color: var(--brass-bright);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.ghost-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--ink-text-dim);
  padding: 7px 14px;
  border-radius: 7px;
  font-size: 0.85rem;
  transition: border-color 0.15s, color 0.15s;
}
.ghost-btn:hover { border-color: var(--brass); color: var(--ink-text); }

.icon-btn {
  padding: 7px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ===================== Modal ===================== */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 50;
}

.modal-card {
  width: 100%;
  max-width: 360px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 26px 24px;
  box-shadow: var(--shadow);
}

.modal-card h2 {
  font-family: var(--serif);
  font-weight: 500;
  font-size: 1.3rem;
  margin: 0 0 18px;
}

#password-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

#password-form label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.85rem;
  color: var(--ink-text-dim);
}

#password-form input {
  background: var(--ink);
  border: 1px solid var(--border);
  color: var(--ink-text);
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 0.9rem;
  outline: none;
}
#password-form input:focus { border-color: var(--brass); }

.password-success {
  color: var(--verdigris);
  font-size: 0.85rem;
  margin: 0;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 4px;
}

#password-submit-btn {
  background: var(--brass);
  color: #1A1206;
  border: none;
  padding: 9px 18px;
  border-radius: 7px;
  font-weight: 600;
  font-size: 0.88rem;
}
#password-submit-btn:hover { background: var(--brass-bright); }
#password-submit-btn:disabled { opacity: 0.6; }

.layout {
  flex: 1;
  display: flex;
  max-width: 1080px;
  width: 100%;
  margin: 0 auto;
}

/* ===================== Category nav ===================== */
.tabs {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 20px 12px;
  width: 168px;
  flex-shrink: 0;
  border-right: 1px solid var(--border);
}

.tab {
  display: flex;
  align-items: center;
  gap: 10px;
  background: transparent;
  border: none;
  color: var(--ink-text-dim);
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 0.9rem;
  text-align: left;
  transition: background 0.15s, color 0.15s;
}
.tab svg { flex-shrink: 0; }
.tab:hover { background: var(--panel-2); color: var(--ink-text); }
.tab.active { background: var(--panel-2); color: var(--brass-bright); }

/* ===================== Content ===================== */
.content {
  flex: 1;
  padding: 24px;
  min-width: 0;
}

.uploader {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 26px;
}

.dropzone {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  border: 1.5px dashed var(--border);
  border-radius: var(--radius);
  padding: 26px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.dropzone:hover { border-color: var(--brass); background: var(--panel); }
.dropzone.has-file { border-color: var(--verdigris); border-style: solid; background: var(--panel); }
.dz-title { font-family: var(--serif); font-size: 1.05rem; color: var(--ink-text); }
.dz-sub { font-size: 0.8rem; color: var(--ink-text-dim); }

.caption-input, .text-area {
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--ink-text);
  padding: 10px 13px;
  border-radius: 8px;
  font-size: 0.9rem;
  outline: none;
  resize: vertical;
}
.caption-input:focus, .text-area:focus { border-color: var(--brass); }

.save-btn {
  align-self: flex-start;
  background: var(--verdigris);
  color: #0D1613;
  border: none;
  padding: 10px 20px;
  border-radius: 8px;
  font-weight: 600;
  font-size: 0.88rem;
}
.save-btn:hover { filter: brightness(1.1); }
.save-btn:disabled { opacity: 0.6; }

.progress-bar {
  height: 4px;
  background: var(--panel-2);
  border-radius: 2px;
  margin-bottom: 20px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  width: 0%;
  background: var(--brass);
  transition: width 0.2s;
}

.empty-state {
  color: var(--ink-text-dim);
  text-align: center;
  padding: 40px 0;
  font-size: 0.92rem;
}

/* ===================== Item grid ===================== */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 14px;
}

.item-card {
  background: var(--paper);
  color: #221D14;
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: 0 4px 14px rgba(0,0,0,0.25);
}

.item-media {
  width: 100%;
  aspect-ratio: 4/3;
  background: var(--paper-dim);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.item-media img, .item-media video { width: 100%; height: 100%; object-fit: cover; }
.item-media.audio-wrap { flex-direction: column; gap: 8px; padding: 10px; aspect-ratio: auto; }
.item-media.audio-wrap audio { width: 100%; }

.item-body {
  padding: 11px 13px 13px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1;
}

.item-title {
  font-family: var(--serif);
  font-size: 0.98rem;
  line-height: 1.3;
  word-break: break-word;
}

.item-text-preview {
  font-size: 0.85rem;
  color: #4A4331;
  line-height: 1.4;
  white-space: pre-wrap;
  max-height: 4.8em;
  overflow: hidden;
}

.item-link {
  font-size: 0.85rem;
  color: var(--verdigris);
  word-break: break-all;
  text-decoration: none;
}
.item-link:hover { text-decoration: underline; }

.item-date {
  font-size: 0.72rem;
  color: #7A7159;
  margin-top: auto;
}

.item-actions {
  display: flex;
  gap: 6px;
  margin-top: 4px;
}

.item-btn {
  flex: 1;
  background: rgba(0,0,0,0.06);
  border: none;
  color: #221D14;
  padding: 7px 0;
  border-radius: 6px;
  font-size: 0.78rem;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  transition: background 0.15s;
}
.item-btn:hover { background: rgba(0,0,0,0.12); }
.item-btn.danger { color: var(--rust); }
.item-btn.danger:hover { background: rgba(166,75,60,0.15); }

/* ===================== Toast ===================== */
.toast {
  position: fixed;
  bottom: calc(20px + env(safe-area-inset-bottom, 0px));
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--panel-2);
  color: var(--ink-text);
  border: 1px solid var(--border);
  padding: 10px 18px;
  border-radius: 8px;
  font-size: 0.85rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 100;
  box-shadow: var(--shadow);
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ===================== Dark/light aware (default is our own dark theme) ===================== */
:root:not([data-theme="light"]) { color-scheme: dark; }

/* ===================== Responsive ===================== */
@media (max-width: 720px) {
  .layout { flex-direction: column; }

  .tabs {
    flex-direction: row;
    width: 100%;
    order: 2;
    position: sticky;
    bottom: 0;
    bottom: env(safe-area-inset-bottom, 0px);
    background: var(--panel);
    border-right: none;
    border-top: 1px solid var(--border);
    padding: 8px 6px calc(8px + env(safe-area-inset-bottom, 0px));
    justify-content: space-between;
    z-index: 10;
  }
  .tab {
    flex-direction: column;
    gap: 3px;
    flex: 1;
    padding: 6px 2px;
    font-size: 0.68rem;
    text-align: center;
    align-items: center;
  }

  .content { order: 1; padding: 16px; padding-bottom: 90px; }

  .grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
}
