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

:root {
  --bg: #f5f5f7;
  --bg-card: #ffffff;
  --bg-hover: #f0f0f2;
  --bg-input: #f5f5f7;
  --text: #1d1d1f;
  --text-secondary: #86868b;
  --border: #d2d2d7;
  --primary: #0071e3;
  --primary-hover: #0077ed;
  --danger: #ff3b30;
  --danger-hover: #ff453a;
  --shadow: 0 1px 3px rgba(0,0,0,0.08);
  --shadow-lg: 0 4px 16px rgba(0,0,0,0.12);
  --radius: 12px;
  --radius-sm: 8px;
  --header-h: 56px;
  --tab-h: 52px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1c1c1e;
    --bg-card: #2c2c2e;
    --bg-hover: #3a3a3c;
    --bg-input: #3a3a3c;
    --text: #f5f5f7;
    --text-secondary: #98989d;
    --border: #48484a;
    --shadow: 0 1px 3px rgba(0,0,0,0.3);
    --shadow-lg: 0 4px 16px rgba(0,0,0,0.4);
  }
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

/* ===== Login Screen ===== */
.screen {
  min-height: 100dvh;
}

.login-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100dvh;
  padding: 24px;
}

.login-icon {
  font-size: 64px;
  margin-bottom: 16px;
}

.login-container h1 {
  font-size: 28px;
  font-weight: 700;
  margin-bottom: 32px;
}

#login-form {
  width: 100%;
  max-width: 340px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

#login-form input {
  width: 100%;
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  color: var(--text);
  font-size: 16px;
  outline: none;
  transition: border-color 0.2s;
}

#login-form input:focus {
  border-color: var(--primary);
}

.error-text {
  color: var(--danger);
  font-size: 14px;
  text-align: center;
  margin-top: 8px;
}

/* ===== Buttons ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 20px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}

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

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
}
.btn-ghost:hover {
  background: var(--bg-hover);
  color: var(--text);
}

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

.btn-sm {
  padding: 8px 14px;
  font-size: 13px;
}

/* ===== App Layout ===== */
#app-screen {
  display: flex;
  flex-direction: column;
  height: 100dvh;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--header-h);
  padding: 0 16px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-card);
  flex-shrink: 0;
}

.app-title {
  font-size: 20px;
  font-weight: 700;
}

.header-actions {
  display: flex;
  gap: 4px;
}

/* ===== Tab Navigation ===== */
.tab-nav {
  display: flex;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.tab-btn {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 12px 0;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-secondary);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
}

.tab-btn.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

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

/* ===== Content ===== */
.content {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.tab-content {
  display: none;
  padding: 16px;
  max-width: 800px;
  margin: 0 auto;
  width: 100%;
}

.tab-content.active {
  display: block;
}

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

.tab-header h2 {
  font-size: 22px;
  font-weight: 700;
}

/* ===== Notes ===== */
.notes-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.note-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  cursor: pointer;
  transition: all 0.15s;
  box-shadow: var(--shadow);
}

.note-card:hover {
  box-shadow: var(--shadow-lg);
  transform: translateY(-1px);
}

.note-card:active {
  transform: translateY(0);
}

.note-card-title {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 4px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.note-card-preview {
  font-size: 14px;
  color: var(--text-secondary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  margin-bottom: 8px;
}

.note-card-date {
  font-size: 12px;
  color: var(--text-secondary);
}

/* ===== Files ===== */
.drop-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 32px;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s;
  margin-bottom: 16px;
}

.drop-zone:hover,
.drop-zone.drag-over {
  border-color: var(--primary);
  background: rgba(0, 113, 227, 0.05);
}

.drop-zone-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  color: var(--text-secondary);
}

.drop-zone-content svg {
  opacity: 0.5;
}

.files-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.file-card {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
  box-shadow: var(--shadow);
}

.file-icon {
  font-size: 28px;
  flex-shrink: 0;
}

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

.file-name {
  font-size: 15px;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-meta {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 2px;
}

.file-actions {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}

.file-actions .btn {
  padding: 8px;
  border-radius: var(--radius-sm);
}

/* ===== Links ===== */
.links-notice {
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 16px;
  padding: 8px 12px;
  background: var(--bg-hover);
  border-radius: var(--radius-sm);
}

.links-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.link-card {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
  box-shadow: var(--shadow);
}

.link-icon {
  font-size: 24px;
  flex-shrink: 0;
  margin-top: 2px;
}

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

.link-url {
  font-size: 15px;
  font-weight: 500;
  color: var(--primary);
  text-decoration: none;
  word-break: break-all;
  display: block;
}

.link-url:hover {
  text-decoration: underline;
}

.link-memo {
  font-size: 14px;
  color: var(--text);
  margin-top: 4px;
  white-space: pre-wrap;
  word-break: break-word;
}

.link-meta {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 6px;
}

.link-actions {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}

.link-actions .btn {
  padding: 8px;
  border-radius: var(--radius-sm);
}

.link-memo-input {
  width: 100%;
  min-height: 80px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
  resize: vertical;
  outline: none;
  font-family: inherit;
}

.link-memo-input:focus {
  border-color: var(--primary);
}

/* ===== Empty State ===== */
.empty-state {
  display: none;
  text-align: center;
  padding: 48px 24px;
  color: var(--text-secondary);
}

.empty-state.visible {
  display: block;
}

.empty-icon {
  font-size: 48px;
  margin-bottom: 12px;
}

.text-muted {
  color: var(--text-secondary);
  font-size: 14px;
  margin-top: 4px;
}

/* ===== Modal ===== */
.modal[hidden] {
  display: none !important;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.modal-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.4);
}

.modal-content {
  position: relative;
  background: var(--bg-card);
  width: 100%;
  max-width: 600px;
  max-height: 90dvh;
  border-radius: var(--radius) var(--radius) 0 0;
  display: flex;
  flex-direction: column;
  animation: slideUp 0.25s ease;
}

@keyframes slideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

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

.modal-header h3 {
  font-size: 18px;
  font-weight: 600;
}

.modal-close {
  font-size: 24px;
  padding: 4px 8px !important;
}

.modal-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.note-title-input {
  width: 100%;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  color: var(--text);
  font-size: 18px;
  font-weight: 600;
  outline: none;
}

.note-title-input:focus {
  border-color: var(--primary);
}

.note-content-input {
  width: 100%;
  min-height: 200px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  color: var(--text);
  font-size: 15px;
  line-height: 1.6;
  resize: vertical;
  outline: none;
  font-family: inherit;
}

.note-content-input:focus {
  border-color: var(--primary);
}

.modal-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  padding-bottom: calc(12px + var(--safe-bottom));
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.modal-footer-right {
  display: flex;
  gap: 8px;
}

/* ===== Toast ===== */
.toast {
  position: fixed;
  bottom: calc(24px + var(--safe-bottom));
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: var(--bg);
  padding: 12px 24px;
  border-radius: 100px;
  font-size: 14px;
  font-weight: 500;
  z-index: 200;
  animation: fadeInUp 0.3s ease;
  box-shadow: var(--shadow-lg);
}

@keyframes fadeInUp {
  from { opacity: 0; transform: translateX(-50%) translateY(16px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* ===== Upload Progress ===== */
.upload-progress {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 8px;
}

.progress-bar {
  flex: 1;
  height: 4px;
  background: var(--bg-hover);
  border-radius: 2px;
  overflow: hidden;
}

.progress-bar-fill {
  height: 100%;
  background: var(--primary);
  border-radius: 2px;
  transition: width 0.2s;
}

/* ===== Desktop (768px+) ===== */
@media (min-width: 768px) {
  .modal {
    align-items: center;
  }

  .modal-content {
    border-radius: var(--radius);
    max-height: 80dvh;
    animation: fadeIn 0.2s ease;
  }

  @keyframes fadeIn {
    from { opacity: 0; transform: scale(0.95); }
    to { opacity: 1; transform: scale(1); }
  }

  .tab-nav {
    justify-content: flex-start;
    gap: 0;
    padding: 0 16px;
  }

  .tab-btn {
    flex: none;
    padding: 12px 24px;
  }

  .tab-content {
    padding: 24px;
  }

  .drop-zone {
    padding: 48px;
  }

  .note-content-input {
    min-height: 300px;
  }

  .modal-footer {
    padding-bottom: 12px;
  }

  .toast {
    bottom: 24px;
  }
}
