:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --border: #dcdfe4;
  --text: #1c2128;
  --muted: #57606a;
  --primary: #1f6feb;
  --primary-hover: #1558c0;
  --danger: #cf222e;
  --danger-hover: #a40e26;
  --warn-bg: #fff8c5;
  --warn-border: #d4a72c;
  --ok: #1a7f37;
  --radius: 8px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1117;
    --surface: #161b22;
    --surface-2: #21262d;
    --border: #30363d;
    --text: #e6edf3;
    --muted: #8b949e;
    --primary: #2f81f7;
    --primary-hover: #58a6ff;
    --danger: #f85149;
    --danger-hover: #da3633;
    --warn-bg: #3b2e00;
    --warn-border: #9e6a03;
    --ok: #3fb950;
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
  font-size: 14px;
}

.hidden {
  display: none !important;
}

.muted {
  color: var(--muted);
}

.error-text {
  color: var(--danger);
  margin: 8px 0 0;
  font-size: 13px;
}

.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
}

.topbar-inner {
  max-width: 1120px;
  margin: 0 auto;
  padding: 10px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

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

.brand-title {
  font-size: 18px;
  font-weight: 700;
}

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--muted);
}

.badge.unlocked {
  color: var(--ok);
  border-color: var(--ok);
}

.storage-widget {
  flex: 1;
  min-width: 180px;
  max-width: 340px;
}

.storage-labels {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  margin-bottom: 4px;
}

.progress-track {
  height: 7px;
  background: var(--surface-2);
  border-radius: 999px;
  overflow: hidden;
  border: 1px solid var(--border);
}

.progress-fill {
  height: 100%;
  width: 0%;
  background: var(--primary);
  transition: width 0.2s ease;
}

.progress-fill.warn {
  background: #d29922;
}

.progress-fill.full {
  background: var(--danger);
}

.banner {
  max-width: 1120px;
  margin: 12px auto 0;
  padding: 10px 16px;
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.banner-warn {
  background: var(--warn-bg);
  border: 1px solid var(--warn-border);
}

.container {
  max-width: 1120px;
  margin: 16px auto 48px;
  padding: 0 16px;
}

.tabs {
  display: flex;
  gap: 6px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 16px;
}

.tab {
  background: transparent;
  border: 1px solid transparent;
  border-bottom: none;
  padding: 9px 16px;
  font-size: 14px;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  border-radius: var(--radius) var(--radius) 0 0;
}

.tab:hover {
  color: var(--text);
}

.tab.active {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border);
  margin-bottom: -1px;
  padding-bottom: 10px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 7px 13px;
  font-size: 13px;
  font-weight: 600;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
}

.btn:hover {
  background: var(--surface-2);
}

.btn-primary {
  background: var(--primary);
  border-color: var(--primary);
  color: #ffffff;
}

.btn-primary:hover {
  background: var(--primary-hover);
}

.btn-danger {
  background: var(--danger);
  border-color: var(--danger);
  color: #ffffff;
}

.btn-danger:hover {
  background: var(--danger-hover);
}

.btn-sm {
  padding: 4px 9px;
  font-size: 12px;
}

.btn-icon {
  background: transparent;
  border: none;
  font-size: 22px;
  line-height: 1;
  color: var(--muted);
  cursor: pointer;
  padding: 2px 6px;
}

.btn-icon:hover {
  color: var(--text);
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 16px;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.panel-header h2,
.panel-header h3 {
  margin: 0;
  font-size: 16px;
}

.dropzone {
  background: var(--surface);
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.dropzone.drag-over {
  border-color: var(--primary);
  background: var(--surface-2);
}

.dropzone-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

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

.lock-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px 20px;
  max-width: 440px;
  margin: 32px auto;
  text-align: center;
}

.lock-panel h2 {
  margin-top: 0;
}

.inline-form {
  display: flex;
  gap: 8px;
  margin-top: 14px;
}

input[type="text"],
input[type="password"],
input[type="number"],
input[type="search"],
select,
textarea {
  width: 100%;
  padding: 8px 10px;
  font-size: 14px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-family: inherit;
}

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.breadcrumbs {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  font-size: 13px;
}

.crumb-btn {
  background: none;
  border: none;
  color: var(--primary);
  font-weight: 600;
  cursor: pointer;
  padding: 2px 4px;
  font-size: 13px;
}

.crumb-btn:hover {
  text-decoration: underline;
}

.toolbar-right {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.search-input {
  width: 210px !important;
}

.table-wrap {
  overflow-x: auto;
}

.items-table {
  width: 100%;
  border-collapse: collapse;
}

.items-table th,
.items-table td {
  padding: 9px 10px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: middle;
}

.items-table th {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--muted);
}

.items-table tr:last-child td {
  border-bottom: none;
}

.col-size {
  width: 95px;
  white-space: nowrap;
}

.col-date {
  width: 155px;
  white-space: nowrap;
}

.col-actions {
  width: 1%;
  white-space: nowrap;
}

.item-name-cell {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.item-main {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 500;
  word-break: break-word;
}

.item-link {
  background: none;
  border: none;
  padding: 0;
  color: var(--text);
  font: inherit;
  font-weight: 600;
  text-align: left;
  cursor: pointer;
}

.item-link:hover {
  color: var(--primary);
  text-decoration: underline;
}

.kind-tag {
  font-size: 11px;
  padding: 1px 6px;
  border-radius: 4px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--muted);
  flex-shrink: 0;
}

.note-snippet {
  font-size: 12px;
  color: var(--muted);
  max-width: 480px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.row-actions {
  display: flex;
  gap: 6px;
  flex-wrap: nowrap;
}

.empty-state {
  text-align: center;
  padding: 28px 12px;
  color: var(--muted);
}

.transfers-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.transfer-item {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px 12px;
  background: var(--bg);
}

.transfer-top {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 6px;
  flex-wrap: wrap;
}

.transfer-controls {
  display: flex;
  gap: 6px;
  align-items: center;
}

.settings-grid {
  display: grid;
  grid-template-columns: 1.1fr 0.9fr;
  gap: 16px;
}

@media (max-width: 820px) {
  .settings-grid {
    grid-template-columns: 1fr;
  }
  .col-date {
    display: none;
  }
}

.settings-form,
.modal-body {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.field > span {
  font-size: 13px;
  font-weight: 600;
}

.checkbox-field {
  flex-direction: row;
  align-items: center;
  gap: 8px;
}

.checkbox-field input {
  width: auto;
}

.breakdown-list,
.shares-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.breakdown-row,
.share-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
}

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

.modal {
  width: 100%;
  max-width: 580px;
  max-height: 90vh;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.modal-sm {
  max-width: 420px;
}

.modal-lg {
  max-width: 920px;
}

.modal-header {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.modal-header h3 {
  margin: 0;
  font-size: 16px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

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

.modal-body {
  padding: 16px;
  overflow-y: auto;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 6px;
}

.preview-body {
  min-height: 220px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.preview-body img {
  max-width: 100%;
  max-height: 72vh;
  border-radius: 4px;
}

.preview-body video,
.preview-body audio {
  width: 100%;
  max-height: 72vh;
}

.preview-body iframe {
  width: 100%;
  height: 72vh;
  border: 1px solid var(--border);
  border-radius: 4px;
}

.preview-body pre,
.share-note {
  width: 100%;
  max-height: 68vh;
  overflow: auto;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 12px;
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13px;
}

.share-result {
  display: flex;
  gap: 8px;
  align-items: center;
}

.toast-container {
  position: fixed;
  right: 16px;
  bottom: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 80;
}

.toast {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 4px solid var(--primary);
  border-radius: 6px;
  padding: 10px 14px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
  max-width: 340px;
  font-size: 13px;
}

.toast.error {
  border-left-color: var(--danger);
}

.share-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.share-card {
  width: 100%;
  max-width: 560px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
}

.share-card h1 {
  margin: 8px 0;
  font-size: 20px;
  word-break: break-word;
}

.share-actions {
  display: flex;
  gap: 10px;
  margin-top: 18px;
  flex-wrap: wrap;
}
