:root {
  --ink: #102a2a;
  --ink-soft: #5f7473;
  --brand: #007f73;
  --brand-dark: #00665d;
  --pale: #e6f4f1;
  --canvas: #f5f8f7;
  --surface: #ffffff;
  --line: #d5e1df;
  --danger: #a3271b;
  --danger-pale: #fbebe8;
  --radius: 12px;
  color-scheme: light;
}

* { box-sizing: border-box; }

/* The hidden attribute must win over the display values set further down. */
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background: var(--canvas);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

h1, h2, p, ul { margin: 0; }
ul { padding: 0; list-style: none; }

.visually-hidden {
  position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

.muted { color: var(--ink-soft); }
.small { font-size: .84rem; }

.top {
  max-width: 880px;
  margin: 0 auto;
  padding: calc(14px + env(safe-area-inset-top)) 16px 6px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand h1 { font-size: 1.3rem; letter-spacing: -.01em; white-space: nowrap; }
.version { color: var(--ink-soft); font-size: .78rem; font-weight: 600; }
.top-actions { display: flex; gap: 6px; }

main {
  max-width: 880px;
  margin: 0 auto;
  padding: 8px 16px calc(40px + env(safe-area-inset-bottom));
  display: grid;
  gap: 14px;
}
#storagePanel { display: grid; gap: 14px; }

.card {
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.button {
  min-height: 40px;
  padding: 0 16px;
  border: 1px solid transparent;
  border-radius: 9px;
  font: inherit;
  font-weight: 650;
  cursor: pointer;
  white-space: nowrap;
}
.button:disabled { cursor: default; opacity: .45; }
.button:focus-visible, .choice:focus-visible, input:focus-visible { outline: 3px solid rgba(0, 127, 115, .35); outline-offset: 2px; }
.button--primary { color: #fff; background: var(--brand); }
.button--primary:not(:disabled):hover { background: var(--brand-dark); }
.button--quiet { color: var(--brand-dark); background: transparent; border-color: var(--line); }
.button--quiet:not(:disabled):hover { background: var(--pale); }
.button--danger { color: var(--danger); background: var(--surface); border-color: #e3bdb7; }
.button--danger:not(:disabled):hover { background: var(--danger-pale); }
.button--small { min-height: 34px; padding: 0 12px; font-size: .88rem; }

.key-panel { display: grid; gap: 12px; max-width: 560px; }
.key-panel h2 { font-size: 1.1rem; }
.key-form { display: flex; gap: 8px; }
.key-form input {
  flex: 1;
  min-width: 0;
  min-height: 42px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 9px;
  font: inherit;
  color: var(--ink);
  background: var(--surface);
}
.message { padding: 10px 12px; border-radius: 9px; color: var(--danger); background: var(--danger-pale); font-size: .92rem; }

.usage { display: grid; gap: 10px; }
.usage-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.usage-head strong { font-size: 1.05rem; }
.usage-bar { height: 12px; display: flex; overflow: hidden; border-radius: 999px; background: var(--pale); }
.usage-fill { height: 100%; width: 0; background: var(--brand); transition: width .25s ease; }
.usage-fill--reserved { background: #8cc9c1; }
.usage-bar.is-nearly-full .usage-fill:not(.usage-fill--reserved) { background: #b9770e; }

.dropzone {
  display: grid;
  justify-items: center;
  gap: 6px;
  border-style: dashed;
  border-width: 2px;
  text-align: center;
  transition: background .15s ease, border-color .15s ease;
}
.dropzone.is-dragging { border-color: var(--brand); background: var(--pale); }
.dropzone-title { font-weight: 700; }

.upload-list { width: 100%; display: grid; gap: 8px; text-align: left; }
.upload-list:not(:empty) { margin-top: 12px; }
.upload-item {
  padding: 10px 12px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 4px 10px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--canvas);
}
.upload-name { overflow: hidden; font-weight: 600; text-overflow: ellipsis; white-space: nowrap; }
.upload-status { grid-column: 1; font-size: .84rem; color: var(--ink-soft); }
.upload-item.is-failed .upload-status { color: var(--danger); }
.upload-item .button { grid-column: 2; grid-row: 1 / span 2; }
.upload-progress { grid-column: 1 / -1; height: 6px; overflow: hidden; border-radius: 999px; background: var(--line); }
.upload-progress span { display: block; height: 100%; width: 0; background: var(--brand); transition: width .2s linear; }
.upload-item.is-done .upload-progress span { background: #4fa99e; }
.upload-item.is-failed .upload-progress span { background: var(--danger); }

.files { padding: 0; overflow: hidden; }
.files-toolbar {
  padding: 12px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  border-bottom: 1px solid var(--line);
  background: #fbfdfc;
}
.select-all { display: flex; align-items: center; gap: 10px; font-weight: 600; cursor: pointer; }
.toolbar-actions { display: flex; gap: 8px; }
input[type="checkbox"] { width: 20px; height: 20px; margin: 0; accent-color: var(--brand); cursor: pointer; }

.file-row {
  padding: 12px 18px;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  border-bottom: 1px solid var(--line);
}
.file-row:last-child { border-bottom: 0; }
.file-row.is-selected { background: #f1f9f7; }
.file-main { min-width: 0; display: grid; gap: 2px; cursor: pointer; }
.file-name { overflow: hidden; font-weight: 600; text-overflow: ellipsis; white-space: nowrap; }
.file-meta { color: var(--ink-soft); font-size: .84rem; }
.file-meta .soon { color: #9a5b00; font-weight: 600; }
.file-actions { display: flex; gap: 6px; }
.empty { padding: 28px 18px; text-align: center; }

.dialog {
  width: min(460px, calc(100vw - 32px));
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 14px;
  color: var(--ink);
  background: var(--surface);
  box-shadow: 0 18px 50px rgba(16, 42, 42, .22);
}
.dialog::backdrop { background: rgba(16, 42, 42, .38); }
.dialog h2 { margin-bottom: 8px; font-size: 1.15rem; }
.dialog-summary { margin-bottom: 10px; font-weight: 600; overflow-wrap: anywhere; }
.choice-list { margin: 12px 0; display: grid; gap: 8px; }
.choice {
  padding: 12px 14px;
  display: grid;
  gap: 2px;
  text-align: left;
  border: 1px solid var(--line);
  border-radius: 10px;
  font: inherit;
  color: var(--ink);
  background: var(--surface);
  cursor: pointer;
}
.choice:hover { border-color: var(--brand); background: var(--pale); }
.choice:disabled { cursor: default; opacity: .5; }
.dialog-actions { margin-top: 14px; display: flex; justify-content: flex-end; gap: 8px; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(18px + env(safe-area-inset-bottom));
  max-width: min(520px, calc(100vw - 32px));
  padding: 11px 16px;
  transform: translateX(-50%);
  border-radius: 10px;
  color: #fff;
  background: var(--ink);
  box-shadow: 0 8px 24px rgba(16, 42, 42, .25);
  font-size: .92rem;
}
.toast.is-error { background: var(--danger); }

@media (max-width: 560px) {
  .file-row { grid-template-columns: auto minmax(0, 1fr); }
  .file-actions { grid-column: 2; }
  .key-form { flex-direction: column; }
  .version { display: none; }
  .files-toolbar { padding: 12px 14px; }
  .file-row { padding: 12px 14px; }
}
