/* ════════════════════════════════════════════════════════
  TETE — Design System
  Industrial · Encryption Tool · Dark / Light
  ════════════════════════════════════════════════════════ */

@import url('https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;500;600&family=Outfit:wght@400;500;600;700&display=swap');

/* ─── Theme Tokens ─── */
:root {
  --font: 'Outfit', -apple-system, sans-serif;
  --font-mono: 'JetBrains Mono', 'SF Mono', 'Cascadia Code', monospace;
  --radius-sm: 4px;
  --radius-md: 6px;
  --radius-lg: 10px;
  --radius-xl: 14px;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --z-dropdown: 100;
  --z-modal: 5000;
  --z-toast: 10000;
}

/* ─── Dark (default) ─── */
[data-theme="dark"] {
  --canvas: #0b0b0f;
  --surface-1: #101016;
  --surface-2: #15151d;
  --surface-3: #1c1c28;
  --surface-4: #24243a;
  --ink: #efeff5;
  --ink-2: #b0b0c8;
  --ink-3: #707090;
  --ink-4: #484860;
  --accent: #00d4aa;
  --accent-hover: #00f0c0;
  --accent-soft: rgba(0, 212, 170, 0.1);
  --accent-soft-2: rgba(0, 212, 170, 0.22);
  --danger: #ff4d6a;
  --danger-soft: rgba(255, 77, 106, 0.1);
  --warn: #f5a623;
  --warn-soft: rgba(245, 166, 35, 0.08);
  --border: #1e1e2c;
  --border-strong: #2a2a3e;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.5);
  --shadow-md: 0 4px 24px rgba(0, 0, 0, 0.5);
  --shadow-lg: 0 8px 48px rgba(0, 0, 0, 0.6);
  --toast-bg: var(--surface-3);
  --toast-border: var(--border-strong);
  --overlay: rgba(0, 0, 0, 0.75);
}

/* ─── Light ─── */
[data-theme="light"] {
  --canvas: #f4f4f8;
  --surface-1: #ffffff;
  --surface-2: #f0f0f5;
  --surface-3: #e6e6ef;
  --surface-4: #d8d8e8;
  --ink: #10101a;
  --ink-2: #404058;
  --ink-3: #707088;
  --ink-4: #a0a0b4;
  --accent: #009977;
  --accent-hover: #00b386;
  --accent-soft: rgba(0, 153, 119, 0.08);
  --accent-soft-2: rgba(0, 153, 119, 0.18);
  --danger: #d63850;
  --danger-soft: rgba(214, 56, 80, 0.08);
  --warn: #c88a10;
  --warn-soft: rgba(200, 138, 16, 0.06);
  --border: #d4d4e0;
  --border-strong: #c0c0d0;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.06);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.1);
  --toast-bg: var(--surface-1);
  --toast-border: var(--border-strong);
  --overlay: rgba(0, 0, 0, 0.4);
}

/* ─── Reset ─── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* ─── Body ─── */
body {
  font-family: var(--font-mono);
  background: var(--canvas);
  color: var(--ink);
  min-height: 100vh;
  line-height: 1.7;
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
  transition: background 0.25s var(--ease), color 0.25s var(--ease);
}

::selection { background: var(--accent); color: var(--canvas); }

/* ─── Ambient Grid (dark only) ─── */
[data-theme="dark"] body::before {
  content: '';
  position: fixed;
  inset: 0;
  background-image:
    linear-gradient(var(--border) 1px, transparent 1px),
    linear-gradient(90deg, var(--border) 1px, transparent 1px);
  background-size: 48px 48px;
  mask-image: radial-gradient(ellipse 80% 60% at 50% 0%, black 20%, transparent 70%);
  -webkit-mask-image: radial-gradient(ellipse 80% 60% at 50% 0%, black 20%, transparent 70%);
  pointer-events: none;
  z-index: 0;
}

[data-theme="dark"] body::after {
  content: '';
  position: fixed;
  top: -40vh;
  left: 50%;
  translate: -50% 0;
  width: 800px;
  height: 600px;
  background: radial-gradient(ellipse, var(--accent-soft) 0%, transparent 70%);
  pointer-events: none;
  z-index: 0;
  opacity: 0.5;
}

/* ─── Layout ─── */
.app-container {
  position: relative;
  z-index: 1;
  max-width: 800px;
  margin: 0 auto;
  padding: 24px 20px 60px;
}

/* ─── Header ─── */
header { margin-bottom: 32px; }

.header-row {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 8px;
  margin-bottom: 28px;
}

.status-badge {
  font-size: 0.72rem;
  color: var(--ink-3);
}

.theme-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--ink-3);
  cursor: pointer;
  transition: all 0.2s var(--ease);
  margin-right: auto;
}

.theme-btn:hover {
  border-color: var(--border-strong);
  color: var(--ink);
  background: var(--surface-2);
}

[data-theme="dark"] .icon-sun { display: block; }
[data-theme="dark"] .icon-moon { display: none; }
[data-theme="light"] .icon-sun { display: none; }
[data-theme="light"] .icon-moon { display: block; }

.admin-badge {
  background: var(--surface-3);
  color: var(--ink-2);
  padding: 3px 10px;
  border-radius: var(--radius-sm);
  font-size: 0.68rem;
  font-weight: 500;
  letter-spacing: 0.04em;
}

.brand {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
}

.brand-mark {
  width: 40px;
  height: 40px;
  flex-shrink: 0;
}

.brand-text { text-align: left; }

.brand-name {
  font-family: var(--font);
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--ink);
  letter-spacing: -0.03em;
  line-height: 1.2;
}

.brand-desc {
  font-size: 0.72rem;
  color: var(--ink-3);
  letter-spacing: 0.02em;
}

/* ─── Tabs ─── */
.tabs {
  display: flex;
  gap: 2px;
  justify-content: center;
  margin-bottom: 28px;
}

.tab {
  padding: 7px 20px;
  background: transparent;
  border: none;
  cursor: pointer;
  font-size: 0.82rem;
  font-weight: 500;
  font-family: var(--font-mono);
  color: var(--ink-3);
  border-radius: var(--radius-sm);
  transition: all 0.2s var(--ease);
}

.tab:hover { color: var(--ink-2); background: var(--surface-2); }

.tab.active {
  color: var(--accent);
  background: var(--accent-soft);
}

.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ─── Cards ─── */
.card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  margin-bottom: 14px;
  transition: border-color 0.2s var(--ease);
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.card-title {
  font-family: var(--font);
  font-size: 1rem;
  font-weight: 600;
  color: var(--ink);
}

/* ─── Dropzone ─── */
.dropzone {
  position: relative;
  border: 1.5px dashed var(--border-strong);
  border-radius: var(--radius-lg);
  padding: 48px 28px;
  text-align: center;
  cursor: pointer;
  transition: all 0.25s var(--ease);
  background: var(--surface-2);
  overflow: hidden;
}

.dropzone::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, var(--accent-soft) 0%, transparent 50%);
  opacity: 0;
  transition: opacity 0.3s var(--ease);
}

.dropzone:hover::before,
.dropzone.dragover::before { opacity: 1; }

.dropzone:hover,
.dropzone.dragover { border-color: var(--accent); }

.dropzone-icon {
  position: relative;
  color: var(--ink-3);
  margin-bottom: 12px;
  display: block;
  margin-inline: auto;
  transition: all 0.3s var(--ease);
}

.dropzone:hover .dropzone-icon,
.dropzone.dragover .dropzone-icon {
  color: var(--accent);
  transform: scale(1.06);
}

.dropzone p {
  position: relative;
  color: var(--ink-2);
  margin-bottom: 3px;
  font-size: 0.88rem;
}

.dropzone .caption {
  position: relative;
  color: var(--ink-4);
  font-size: 0.72rem;
}

.dropzone input[type="file"] { display: none; }

/* ─── Form ─── */
.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 14px;
  margin-top: 16px;
}

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

.field-align { justify-content: flex-end; }

.field-label {
  color: var(--ink-3);
  font-size: 0.72rem;
  font-weight: 500;
  letter-spacing: 0.01em;
}

.input {
  width: 100%;
  padding: 9px 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-family: var(--font-mono);
  color: var(--ink);
  transition: all 0.2s var(--ease);
  outline: none;
}

.input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-soft);
}

.input::placeholder { color: var(--ink-4); }

select.input { cursor: pointer; }

.textarea {
  margin-top: 14px;
  min-height: 140px;
  resize: vertical;
  line-height: 1.6;
}

/* ─── Buttons ─── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: var(--accent);
  color: var(--canvas);
  border: none;
  padding: 9px 20px;
  border-radius: var(--radius-sm);
  font-size: 0.82rem;
  font-weight: 600;
  font-family: var(--font-mono);
  cursor: pointer;
  transition: all 0.2s var(--ease);
  line-height: 1.4;
}

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

.btn:active { transform: scale(0.97); }

.btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
  transform: none;
}

.btn-ghost {
  background: transparent;
  color: var(--ink-2);
  border: 1px solid var(--border);
}

.btn-ghost:hover {
  background: var(--surface-2);
  border-color: var(--border-strong);
  color: var(--ink);
}

.btn-sm { padding: 5px 12px; font-size: 0.74rem; }

.btn-block { width: 100%; }

.actions-end {
  display: flex;
  justify-content: flex-end;
  margin-top: 14px;
}

/* ─── Callout ─── */
.callout {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin-top: 12px;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  font-size: 0.72rem;
  line-height: 1.5;
}

.callout-warn {
  background: var(--warn-soft);
  color: var(--warn);
}

.callout svg {
  flex-shrink: 0;
  margin-top: 2px;
}

/* ─── Selected Files ─── */
.selected-files { margin: 14px 0; }
.selected-file {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin-bottom: 4px;
  font-size: 0.8rem;
}
.selected-file-name { color: var(--ink-2); }
.selected-file-size { color: var(--ink-3); font-size: 0.74rem; }

/* ─── File List ─── */
.file-list { list-style: none; }

.file-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin-bottom: 6px;
  transition: all 0.2s var(--ease);
}

.file-item:hover {
  border-color: var(--border-strong);
  background: var(--surface-3);
}

.file-info { flex: 1; min-width: 0; }

.file-name {
  font-weight: 500;
  color: var(--ink);
  margin-bottom: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 0.85rem;
}

.file-meta {
  font-size: 0.7rem;
  color: var(--ink-3);
}

.empty {
  text-align: center;
  padding: 44px 20px;
  color: var(--ink-3);
  list-style: none;
}

.empty-icon {
  margin-bottom: 10px;
  opacity: 0.3;
}

.empty p { font-size: 0.85rem; }

/* ─── Dropdown Menu ─── */
.dropdown { position: relative; }

.dropdown-menu {
  position: absolute;
  right: 0;
  top: calc(100% + 4px);
  background: var(--surface-3);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  min-width: 180px;
  z-index: var(--z-dropdown);
  display: none;
  overflow: hidden;
}

.dropdown-menu.show { display: block; }

.dropdown-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  color: var(--ink-2);
  text-decoration: none;
  font-size: 0.8rem;
  cursor: pointer;
  border: none;
  background: transparent;
  width: 100%;
  text-align: left;
  font-family: var(--font-mono);
  transition: background 0.12s var(--ease);
}

.dropdown-item:hover { background: var(--surface-4); color: var(--ink); }

.dropdown-item.danger { color: var(--danger); }
.dropdown-item.danger:hover { background: var(--danger-soft); }

.dropdown-icon { width: 16px; text-align: center; }

/* ─── Result Block ─── */
.result-block {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px;
  margin-top: 14px;
}

.result-title {
  font-family: var(--font);
  font-size: 0.85rem;
  margin-bottom: 8px;
  color: var(--accent);
}

.result-link-card {
  background: var(--surface-1);
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  margin-bottom: 6px;
  word-break: break-all;
  border: 1px solid var(--border);
}

.result-link-card:last-child { margin-bottom: 0; }

.result-link-label {
  display: block;
  margin-bottom: 2px;
  font-size: 0.82rem;
}

.result-link-url {
  display: block;
  font-size: 0.72rem;
  color: var(--ink-3);
  font-family: var(--font-mono);
  margin-top: 4px;
  background: var(--surface-2);
  padding: 5px 8px;
  border-radius: var(--radius-xs, 2px);
}

/* ─── Sub Tabs ─── */
.sub-tabs {
  display: flex;
  gap: 3px;
  margin-bottom: 14px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 3px;
}

.sub-tab {
  padding: 6px 14px;
  background: transparent;
  border: none;
  border-radius: var(--radius-xs, 2px);
  cursor: pointer;
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--ink-3);
  font-family: var(--font-mono);
  transition: all 0.2s var(--ease);
  flex: 1;
  text-align: center;
}

.sub-tab:hover { color: var(--ink-2); background: var(--surface-3); }
.sub-tab.active { color: var(--accent); background: var(--accent-soft); }

.sub-tab-panel { display: none; }
.sub-tab-panel.active { display: block; }

.doc-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.doc-box {
  width: 100%;
  min-height: 480px;
  font-family: var(--font-mono);
  font-size: 0.73rem;
  background: var(--surface-2);
  color: var(--ink-2);
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  resize: vertical;
  outline: none;
  line-height: 1.65;
}

.doc-box:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-soft);
}

/* ─── Icon Button ─── */
.icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--ink-3);
  cursor: pointer;
  transition: all 0.2s var(--ease);
}

.icon-btn:hover {
  background: var(--surface-2);
  border-color: var(--border-strong);
  color: var(--ink);
}

/* ─── Loading ─── */
.loading {
  display: inline-block;
  width: 13px;
  height: 13px;
  border: 2px solid rgba(0, 0, 0, 0.1);
  border-top-color: var(--canvas);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  margin-right: 5px;
  vertical-align: middle;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ─── Toast ─── */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  translate: -50% 0;
  background: var(--toast-bg);
  color: var(--ink);
  padding: 9px 20px;
  border-radius: var(--radius-md);
  font-size: 0.8rem;
  font-weight: 500;
  font-family: var(--font-mono);
  box-shadow: var(--shadow-md);
  border: 1px solid var(--toast-border);
  z-index: var(--z-toast);
  opacity: 0;
  translate: -50% 8px;
  transition: all 0.25s var(--ease);
  pointer-events: none;
  white-space: nowrap;
}

.toast.show {
  opacity: 1;
  translate: -50% 0;
  pointer-events: auto;
}

/* ─── Modal ─── */
.modal-mask {
  position: fixed;
  inset: 0;
  background: var(--overlay);
  backdrop-filter: blur(4px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: var(--z-modal);
}

.modal-mask.show { display: flex; }

.modal {
  background: var(--surface-1);
  padding: 28px;
  border-radius: var(--radius-xl);
  max-width: 380px;
  width: 90%;
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--border);
}

.modal-title {
  font-family: var(--font);
  margin-bottom: 6px;
  font-size: 1.05rem;
  color: var(--ink);
  font-weight: 600;
}

.modal-desc {
  color: var(--ink-3);
  margin-bottom: 16px;
  font-size: 0.8rem;
  line-height: 1.5;
}

.modal-input { margin-bottom: 12px; }

.modal-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

/* ─── Note Block ─── */
.note {
  margin-top: 16px;
  padding: 14px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.note-title {
  display: block;
  font-family: var(--font);
  font-size: 0.85rem;
  color: var(--ink-2);
  margin-bottom: 8px;
  font-weight: 500;
}

.note-list {
  color: var(--ink-3);
  font-size: 0.74rem;
  line-height: 1.9;
  padding-left: 16px;
}

/* ─── Utilities ─── */
.mb-lg { margin-bottom: 20px; }

/* ─── Custom Select (JS-created) ─── */
.custom-select-wrapper { position: relative; user-select: none; width: 100%; }
.custom-select-selected {
  display: flex; justify-content: space-between; align-items: center;
  padding: 9px 12px; background: var(--surface-2);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  cursor: pointer; font-size: 0.85rem; font-family: var(--font-mono);
  color: var(--ink); transition: all 0.2s var(--ease);
}
.custom-select-selected:hover { border-color: var(--border-strong); }
.custom-select-wrapper.show .custom-select-selected {
  border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft);
}
.custom-select-text { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.custom-select-arrow { margin-left: 8px; font-size: 0.6rem; color: var(--ink-4); transition: transform 0.2s var(--ease); }
.custom-select-wrapper.show .custom-select-arrow { transform: rotate(180deg); }
.custom-select-options {
  position: absolute; top: calc(100% + 4px); left: 0; right: 0;
  background: var(--surface-3); border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm); box-shadow: var(--shadow-md);
  z-index: var(--z-dropdown); display: none; max-height: 260px; overflow: hidden;
}
.custom-select-wrapper.show .custom-select-options { display: block; }
.custom-select-search {
  width: 100%; padding: 8px 12px; background: var(--surface-2);
  border: none; border-bottom: 1px solid var(--border);
  font-size: 0.8rem; font-family: var(--font-mono); color: var(--ink); outline: none;
}
.custom-select-search:focus { background: var(--surface-3); }
.custom-select-options-list { overflow-y: auto; max-height: 210px; }
.custom-select-option {
  padding: 7px 12px; cursor: pointer; font-size: 0.82rem;
  color: var(--ink-3); transition: background 0.12s var(--ease);
}
.custom-select-option:hover { background: var(--surface-2); color: var(--ink); }
.custom-select-option.selected {
  background: var(--accent); color: var(--canvas); font-weight: 600;
}

/* ─── Select2 Legacy ─── */
.select2-container--default .select2-selection--single {
  background: var(--surface-2) !important;
  border: 1px solid var(--border) !important;
  border-radius: var(--radius-sm) !important;
  height: 38px !important;
}
.select2-container--default .select2-selection--single .select2-selection__rendered {
  line-height: 38px !important;
  color: var(--ink) !important;
  font-family: var(--font-mono) !important;
  font-size: 0.85rem !important;
}
.select2-dropdown {
  background: var(--surface-3) !important;
  border: 1px solid var(--border-strong) !important;
}

/* ─── Responsive ─── */
@media (max-width: 768px) {
  .app-container { padding: 18px 14px; }

  .brand-mark { width: 34px; height: 34px; }
  .brand-name { font-size: 1.25rem; }
  .brand-desc { font-size: 0.68rem; }

  .tabs { width: 100%; }
  .tab { padding: 6px 14px; font-size: 0.78rem; flex: 1; }

  .form-row { grid-template-columns: 1fr; gap: 12px; }

  .dropzone { padding: 36px 20px; }
  .dropzone p { font-size: 0.82rem; }

  .card { padding: 16px; }

  .sub-tabs { flex-wrap: wrap; }
  .sub-tab { padding: 5px 10px; font-size: 0.72rem; }

  .doc-box { min-height: 350px; font-size: 0.68rem; }

  .file-item { flex-direction: column; gap: 8px; padding: 10px; }
  .dropdown { width: 100%; }
  .dropdown-menu { left: 0; right: 0; }

  .modal { max-width: calc(100% - 32px); padding: 22px; }
  .modal-actions { flex-direction: column; gap: 6px; }
  .modal-actions .btn { width: 100%; }

  .btn { width: 100%; justify-content: center; }

  .toast {
    bottom: 16px;
    left: 16px;
    right: 16px;
    translate: 0 0;
    text-align: center;
  }
  .toast.show { translate: 0 0; }

  .selected-files { max-height: 160px; }
}

@media (max-width: 480px) {
  .app-container { padding: 12px 10px; }
  .brand-name { font-size: 1.1rem; }
  .tab { padding: 5px 10px; font-size: 0.72rem; }
  .card { padding: 12px; }
}
