:root {
  --bg: #000000;
  --bg-secondary: rgba(28, 28, 30, 0.85);
  --bg-card: rgba(44, 44, 46, 0.65);
  --bg-elevated: rgba(58, 58, 60, 0.5);
  --text: #f5f5f7;
  --text-muted: rgba(235, 235, 245, 0.6);
  --accent: #0a84ff;
  --accent-dark: #0071e3;
  --success: #30d158;
  --border: rgba(84, 84, 88, 0.36);
  --nav-height: 50px;
  --header-height: 52px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
  --radius-sm: 10px;
  --radius-md: 14px;
  --radius-lg: 20px;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: -apple-system, 'SF Pro Display', 'SF Pro Text', BlinkMacSystemFont, system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100dvh;
  overflow: hidden;
  -webkit-text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
}

/* Header — iOS-style frosted glass */
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: calc(var(--header-height) + var(--safe-top));
  padding: 0 20px;
  padding-top: var(--safe-top);
  background: rgba(28, 28, 30, 0.72);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 0.5px solid var(--border);
  flex-shrink: 0;
  z-index: 50;
}

header h1 {
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.status {
  font-size: 12px;
  color: var(--text-muted);
  transition: color 0.3s;
}

.status.connected {
  color: var(--success);
}

/* Sidebar */
.sidebar {
  position: fixed;
  top: 0;
  left: -280px;
  width: 280px;
  height: 100dvh;
  background: rgba(28, 28, 30, 0.95);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
  z-index: 300;
  display: flex;
  flex-direction: column;
  transition: left 0.25s ease;
  padding-top: var(--safe-top);
}

.sidebar.open {
  left: 0;
}

.sidebar-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 299;
}

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

.sidebar-header h2 {
  font-size: 17px;
  font-weight: 600;
}

.sidebar-new-btn {
  width: 34px;
  height: 34px;
  border: none;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.sidebar-search {
  padding: 8px 12px;
}

.sidebar-search input {
  width: 100%;
  padding: 8px 12px;
  border-radius: 10px;
  border: 0.5px solid var(--border);
  background: rgba(44, 44, 46, 0.5);
  color: var(--text);
  font-size: 14px;
  outline: none;
}

.sidebar-search input::placeholder {
  color: var(--text-muted);
}

.sidebar-search input:focus {
  border-color: var(--accent);
}

.chat-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.chat-list-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px;
  border-radius: 10px;
  cursor: pointer;
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
  transition: background 0.15s;
}

.chat-list-item:active,
.chat-list-item.active {
  background: var(--bg-elevated);
}

.chat-list-item .chat-item-title {
  flex: 1;
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-list-item .chat-item-preview {
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  grid-column: 1 / -1;
}

.chat-list-item .chat-item-date {
  font-size: 11px;
  color: var(--text-muted);
  flex-shrink: 0;
}

.chat-list-item .chat-item-delete {
  width: 28px;
  height: 28px;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: var(--text-muted);
  font-size: 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0.4;
  flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;
}

.chat-list-item:hover .chat-item-delete,
.chat-list-item:active .chat-item-delete {
  opacity: 1;
}

/* Menu Button */
.menu-btn {
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  flex-shrink: 0;
}

/* Views */
.view {
  display: none;
  flex-direction: column;
  height: 100dvh;
}

.view.active {
  display: flex;
}

/* ============ Chat View ============ */
.messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  -webkit-overflow-scrolling: touch;
  position: relative;
}

.msg {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: 18px;
  font-size: 16px;
  line-height: 1.35;
  word-wrap: break-word;
}

.msg.user {
  align-self: flex-end;
  background: var(--accent);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.msg.bot {
  align-self: flex-start;
  background: rgba(44, 44, 46, 0.8);
  border-bottom-left-radius: 4px;
  max-width: 92%;
}

.msg .doc-cards {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 10px;
}

.doc-card {
  display: grid;
  grid-template-columns: 44px 1fr;
  grid-template-rows: auto auto;
  gap: 4px 10px;
  padding: 10px 12px;
  background: var(--bg-card);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  border: 0.5px solid var(--border);
  border-radius: var(--radius-md);
  text-decoration: none;
  color: var(--text);
  transition: background 0.15s;
}

.doc-thumb-wrap {
  grid-row: 1 / 3;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

.doc-page-badge {
  position: absolute;
  bottom: 2px;
  right: 2px;
  background: rgba(0,0,0,0.72);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  line-height: 1;
  padding: 2px 5px;
  border-radius: 8px;
  pointer-events: none;
  letter-spacing: 0.02em;
}

.doc-card-deleted {
  opacity: 0.45;
  pointer-events: none;
}

.doc-deleted-hint {
  font-size: 12px;
  color: var(--text-muted);
  padding: 6px 0;
  display: block;
}

.doc-thumb {
  width: 44px;
  height: 44px;
  border-radius: 8px;
  object-fit: cover;
}

.doc-card .doc-icon {
  font-size: 26px;
}

.doc-card .doc-info {
  min-width: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.doc-text {
  display: none;
}

.doc-actions {
  grid-column: 1 / -1;
  display: flex;
  gap: 6px;
  padding-top: 6px;
  border-top: 0.5px solid var(--border);
  margin-top: 4px;
}

.doc-action-btn {
  flex: 1;
  height: 32px;
  border: none;
  border-radius: 8px;
  background: var(--bg-elevated);
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.15s, color 0.15s;
}

.doc-action-btn:active {
  background: var(--accent);
  color: #fff;
}

.doc-card .doc-name {
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  letter-spacing: -0.01em;
}

.doc-card .doc-meta {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 1px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.msg .typing {
  display: inline-flex;
  gap: 5px;
  padding: 2px 0;
}

.msg .typing span {
  width: 7px;
  height: 7px;
  background: var(--text-muted);
  border-radius: 50%;
  animation: typing 1.4s infinite;
}

.msg .typing span:nth-child(2) { animation-delay: 0.2s; }
.msg .typing span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typing {
  0%, 60%, 100% { opacity: 0.3; transform: translateY(0); }
  30% { opacity: 1; transform: translateY(-5px); }
}

/* Chat Attachment Bar */
.chat-attachment {
  display: flex;
  gap: 8px;
  padding: 8px 12px;
  background: rgba(28, 28, 30, 0.9);
  border-top: 0.5px solid var(--border);
  flex-shrink: 0;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.attach-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  background: var(--bg-card);
  border-radius: 10px;
  flex-shrink: 0;
  max-width: 180px;
}

.attach-thumb {
  width: 32px;
  height: 32px;
  border-radius: 6px;
  object-fit: cover;
  flex-shrink: 0;
}

.attach-icon {
  font-size: 20px;
  flex-shrink: 0;
}

.attach-item-name {
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.attach-item-remove {
  width: 22px;
  height: 22px;
  border: none;
  border-radius: 50%;
  background: rgba(84, 84, 88, 0.5);
  color: var(--text-muted);
  font-size: 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.upload-item {
  padding: 10px 0;
  border-bottom: 0.5px solid var(--border);
}

.upload-item:last-child {
  border-bottom: none;
}

/* Drop Overlay */
.drop-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(10, 132, 255, 0.15);
  border: 2px dashed var(--accent);
  border-radius: var(--radius-md);
  font-size: 17px;
  font-weight: 600;
  color: var(--accent);
  z-index: 10;
  pointer-events: none;
}

/* Chat Input — iMessage style */
.chat-input {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 10px;
  background: rgba(28, 28, 30, 0.72);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
  border-top: 0.5px solid var(--border);
  flex-shrink: 0;
}

.attach-btn {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  flex-shrink: 0;
}

.chat-input input {
  flex: 1;
  padding: 10px 16px;
  border-radius: var(--radius-lg);
  border: 0.5px solid var(--border);
  background: rgba(44, 44, 46, 0.5);
  color: var(--text);
  font-size: 16px;
  outline: none;
  transition: border-color 0.2s;
}

.chat-input input::placeholder {
  color: var(--text-muted);
}

.chat-input input:focus {
  border-color: var(--accent);
}

.chat-input button {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: #fff;
  font-size: 17px;
  cursor: pointer;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.1s, background 0.2s;
}

.chat-input button:active {
  transform: scale(0.92);
  background: var(--accent-dark);
}

/* Upload Result (inline in chat) */
.upload-result-inline {
  margin-top: 4px;
}

.upload-result-header {
  font-size: 14px;
  font-weight: 600;
  color: var(--success);
  margin-bottom: 8px;
}

.upload-result-inline .meta-grid {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 4px 12px;
  font-size: 13px;
}

.upload-result-inline .meta-label {
  color: var(--text-muted);
}

.upload-rohtext {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 8px;
}

.tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.tag {
  padding: 3px 10px;
  background: rgba(10, 132, 255, 0.2);
  color: var(--accent);
  border-radius: 100px;
  font-size: 12px;
  font-weight: 500;
}

/* Lightbox */
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: #000;
  display: flex;
  flex-direction: column;
  padding: 0;
  animation: fadeIn 0.2s;
}

.lightbox-img-wrap {
  flex: 1;
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  gap: 16px;
  padding: 16px 0;
}

.lightbox-img {
  max-width: 100%;
  max-height: none;
  object-fit: contain;
  display: block;
}

.lightbox-page-label {
  color: rgba(255, 255, 255, 0.5);
  font-size: 12px;
  text-align: center;
  margin-bottom: 4px;
}

.ocr-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  display: none;
}

.ocr-overlay.active {
  display: block;
  pointer-events: auto;
}

.ocr-word {
  position: absolute;
  color: transparent;
  user-select: text;
  -webkit-user-select: text;
  cursor: text;
  line-height: 1;
  white-space: nowrap;
}

.ocr-word::selection {
  background: rgba(10, 132, 255, 0.4);
  color: transparent;
}

.lightbox-text-toggle {
  position: absolute;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  padding: 8px 20px;
  border: none;
  border-radius: 100px;
  background: rgba(255, 255, 255, 0.2);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  color: #fff;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  z-index: 202;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.15s;
}

.lightbox-text-toggle:active {
  background: rgba(255, 255, 255, 0.35);
}

.lightbox-text-toggle.text-open {
  bottom: auto;
  top: 12px;
  left: 16px;
  transform: none;
}

.lightbox-text {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  max-height: 40%;
  overflow-y: auto;
  padding: 16px 20px;
  padding-bottom: calc(16px + var(--safe-bottom));
  background: rgba(28, 28, 30, 0.95);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
  color: var(--text);
  font-size: 14px;
  line-height: 1.6;
  white-space: pre-wrap;
  user-select: text;
  -webkit-user-select: text;
  border-top: 0.5px solid var(--border);
  z-index: 203;
  animation: slideUp 0.2s ease;
}

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

.lightbox-close {
  position: absolute;
  top: 12px;
  right: 16px;
  padding-top: var(--safe-top);
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
  font-size: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 204;
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  -webkit-tap-highlight-color: transparent;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* Document Label Badge */
.doc-label {
  display: inline-block;
  margin-left: 8px;
  padding: 2px 8px;
  background: rgba(48, 209, 88, 0.2);
  color: var(--success);
  border-radius: 100px;
  font-size: 11px;
  font-weight: 500;
  vertical-align: middle;
}

/* PDF Export Button */
.pdf-export-btn {
  display: block;
  margin-top: 12px;
  padding: 10px 20px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.15s, transform 0.1s;
}

.pdf-export-btn:active {
  transform: scale(0.96);
  background: var(--accent-dark);
}

/* Login Screen */
.login-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100dvh;
  padding: 20px;
}

.login-title {
  font-size: 34px;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin-bottom: 40px;
}

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

.login-form input {
  padding: 14px 16px;
  border-radius: var(--radius-sm);
  border: 0.5px solid var(--border);
  background: rgba(44, 44, 46, 0.5);
  color: var(--text);
  font-size: 16px;
  outline: none;
}

.login-form input:focus {
  border-color: var(--accent);
}

.login-btn {
  padding: 14px;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: #fff;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
}

.login-btn:active {
  background: var(--accent-dark);
}

.login-hint {
  font-size: 14px;
  color: var(--text-muted);
  text-align: center;
  margin-bottom: 4px;
}

.login-error {
  color: #ff453a;
  font-size: 14px;
  margin-top: 16px;
  text-align: center;
}

.user-name {
  font-size: 13px;
  font-weight: 400;
  color: var(--text-muted);
}

/* Sidebar Footer */
.sidebar-footer {
  padding: 12px;
  border-top: 0.5px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.sidebar-action-btn {
  padding: 10px;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: #fff;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.sidebar-action-btn.secondary {
  background: var(--bg-elevated);
  color: var(--text-muted);
}

/* User Management */
.user-section {
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.user-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px;
  background: var(--bg-elevated);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.user-section-header svg {
  color: var(--text-muted);
  transition: transform 0.2s;
}

.user-section-header.open svg {
  transform: rotate(180deg);
}

.user-panel {
  padding: 8px 0 0;
}

.user-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 8px;
  max-height: 200px;
  overflow-y: auto;
}

.user-list-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 10px;
  background: var(--bg-card);
  border-radius: 8px;
  font-size: 13px;
}

.user-list-item .user-info {
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
}

.user-list-item .user-info-name {
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-list-item .user-info-phone {
  font-size: 11px;
  color: var(--text-muted);
}

.user-list-item .user-info-badge {
  font-size: 10px;
  color: var(--accent);
  font-weight: 600;
  text-transform: uppercase;
}

.user-remove-btn {
  width: 28px;
  height: 28px;
  border: none;
  border-radius: 50%;
  background: rgba(255, 69, 58, 0.15);
  color: #ff453a;
  font-size: 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;
}

.user-actions {
  display: flex;
  gap: 4px;
  align-items: center;
}

.user-qr-btn {
  background: none;
  border: none;
  color: var(--text-muted, #8e8e93);
  cursor: pointer;
  padding: 4px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.user-qr-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  color: var(--accent, #007aff);
}

.add-user-form {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.add-user-form input {
  padding: 10px 12px;
  border-radius: 8px;
  border: 0.5px solid var(--border);
  background: rgba(44, 44, 46, 0.5);
  color: var(--text);
  font-size: 14px;
  outline: none;
}

.add-user-form input:focus {
  border-color: var(--accent);
}

.user-error {
  color: #ff453a;
  font-size: 12px;
  margin-top: 4px;
  text-align: center;
}

/* Delete Button (red tint) */
.doc-delete-btn {
  color: #ff453a !important;
}

.doc-delete-btn:active {
  background: rgba(255, 69, 58, 0.3) !important;
  color: #ff453a !important;
}

/* Inline Edit Form */
.doc-edit-form {
  grid-column: 1 / -1;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding-top: 8px;
  border-top: 0.5px solid var(--border);
  margin-top: 4px;
}

.doc-edit-form .edit-field {
  padding: 8px 10px;
  border-radius: 8px;
  border: 0.5px solid var(--border);
  background: rgba(44, 44, 46, 0.5);
  color: var(--text);
  font-size: 13px;
  outline: none;
  -webkit-appearance: none;
}

.doc-edit-form .edit-field:focus {
  border-color: var(--accent);
}

.doc-edit-form select.edit-field {
  cursor: pointer;
}

.edit-buttons {
  display: flex;
  gap: 6px;
}

.edit-save-btn,
.edit-cancel-btn {
  flex: 1;
  padding: 8px;
  border: none;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.edit-save-btn {
  background: var(--accent);
  color: #fff;
}

.edit-cancel-btn {
  background: var(--bg-elevated);
  color: var(--text-muted);
}

/* Phone login QR hint */
.qr-hint {
  text-align: center;
  color: var(--text-muted);
  font-size: 15px;
  line-height: 1.5;
}

.qr-hint .manual-login-link {
  display: inline-block;
  margin-top: 16px;
  color: var(--accent);
  font-size: 13px;
  cursor: pointer;
  text-decoration: none;
  border: none;
  background: none;
  font-family: inherit;
}

/* ============ Header Tabs ============ */
.header-tabs {
  display: flex;
  gap: 4px;
  background: rgba(44, 44, 46, 0.5);
  border-radius: 8px;
  padding: 2px;
}

.header-tab {
  padding: 5px 14px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.15s, color 0.15s;
}

.header-tab.active {
  background: var(--accent);
  color: #fff;
}

/* ============ Archiv Grid ============ */
.archiv-grid {
  flex: 1;
  overflow-y: hidden;
  display: flex;
  flex-direction: column;
  -webkit-overflow-scrolling: touch;
}

/* Inner scrollable grid of cards */
.archiv-grid-inner {
  flex: 1;
  overflow-y: auto;
  padding: 10px 12px 12px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 10px;
  -webkit-overflow-scrolling: touch;
}

.archiv-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 16px 10px;
  background: var(--bg-card);
  border: 0.5px solid var(--border);
  border-radius: var(--radius-md);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.15s;
  text-align: center;
  height: 155px;
  overflow: hidden;
}

.archiv-card:active {
  background: var(--bg-elevated);
}

.archiv-card .archiv-icon {
  font-size: 32px;
}

.archiv-card .archiv-thumb {
  width: 56px;
  height: 56px;
  border-radius: 10px;
  object-fit: cover;
}

.archiv-thumb-wrap {
  position: relative;
  display: inline-flex;
}

.archiv-card .archiv-title {
  font-size: 13px;
  font-weight: 500;
  line-height: 1.3;
  word-break: break-word;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.archiv-card .archiv-meta {
  font-size: 11px;
  color: var(--text-muted);
}

.archiv-card .archiv-betrag {
  font-size: 13px;
  font-weight: 600;
  color: var(--success);
}

.archiv-empty {
  grid-column: 1 / -1;
  text-align: center;
  padding: 40px 20px;
  color: var(--text-muted);
  font-size: 15px;
}

.archiv-loading {
  grid-column: 1 / -1;
  text-align: center;
  padding: 40px 20px;
  color: var(--text-muted);
  font-size: 14px;
}

.archiv-card {
  position: relative;
}

.archiv-delete-btn {
  position: absolute;
  top: 6px;
  right: 6px;
  background: rgba(255,59,48,0.15);
  border: none;
  border-radius: 6px;
  padding: 4px 6px;
  color: #ff3b30;
  cursor: pointer;
  opacity: 1;
  -webkit-tap-highlight-color: transparent;
}

/* ============ Archiv Toolbar ============ */
.archiv-toolbar {
  display: flex;
  gap: 8px;
  padding: 10px 12px 0;
  flex-shrink: 0;
  align-items: center;
}

.archiv-search-input {
  flex: 1;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  border: 0.5px solid var(--border);
  background: rgba(44, 44, 46, 0.5);
  color: var(--text);
  font-size: 14px;
  outline: none;
}

.archiv-search-input::placeholder {
  color: var(--text-muted);
}

.archiv-search-input:focus {
  border-color: var(--accent);
}

.archiv-sort-select {
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  border: 0.5px solid var(--border);
  background: rgba(44, 44, 46, 0.5);
  color: var(--text);
  font-size: 13px;
  outline: none;
  cursor: pointer;
  -webkit-appearance: none;
  flex-shrink: 0;
}

.archiv-select-btn {
  padding: 8px 12px;
  border: 0.5px solid var(--border);
  border-radius: var(--radius-sm);
  background: rgba(44, 44, 46, 0.5);
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.15s, color 0.15s;
}

.archiv-select-btn.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

/* ============ Auswahl-Modus ============ */
.archiv-card.selected {
  border-color: var(--accent);
  background: rgba(10, 132, 255, 0.15);
}

.archiv-card .select-checkbox {
  position: absolute;
  top: 6px;
  left: 6px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 2px solid var(--text-muted);
  background: transparent;
  display: none;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

.archiv-select-mode .archiv-card .select-checkbox {
  display: flex;
}

.archiv-card.selected .select-checkbox {
  background: var(--accent);
  border-color: var(--accent);
}

.archiv-card.selected .select-checkbox::after {
  content: '';
  width: 6px;
  height: 10px;
  border: 2px solid #fff;
  border-top: none;
  border-left: none;
  transform: rotate(45deg) translate(-1px, -1px);
}

/* Action Bar (Mehrfachauswahl) */
.archiv-action-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  background: rgba(28, 28, 30, 0.95);
  border-top: 0.5px solid var(--border);
  flex-shrink: 0;
}

.archiv-action-bar .action-count {
  flex: 1;
  font-size: 13px;
  color: var(--text-muted);
}

.archiv-action-bar .action-btn {
  padding: 8px 14px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.archiv-action-bar .action-btn-pdf {
  background: var(--accent);
  color: #fff;
}

.archiv-action-bar .action-btn-merge {
  background: var(--bg-elevated);
  color: var(--text);
}

.archiv-action-bar .action-btn-delete {
  background: rgba(255, 69, 58, 0.15);
  color: #ff453a;
}

/* ============ Edit Modal ============ */
.edit-modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 400;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: flex-end;
  animation: fadeIn 0.15s;
}

.edit-modal {
  width: 100%;
  background: rgba(28, 28, 30, 0.98);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  padding: 20px 20px calc(20px + var(--safe-bottom));
  display: flex;
  flex-direction: column;
  gap: 12px;
  animation: slideUp 0.2s ease;
}

.edit-modal-title {
  font-size: 17px;
  font-weight: 600;
  text-align: center;
  margin-bottom: 4px;
}

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

.edit-modal-field label {
  font-size: 12px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.edit-modal-field input,
.edit-modal-field select {
  padding: 11px 14px;
  border-radius: var(--radius-sm);
  border: 0.5px solid var(--border);
  background: rgba(44, 44, 46, 0.5);
  color: var(--text);
  font-size: 16px;
  outline: none;
  -webkit-appearance: none;
}

.edit-modal-field input:focus,
.edit-modal-field select:focus {
  border-color: var(--accent);
}

.edit-modal-buttons {
  display: flex;
  gap: 8px;
  margin-top: 4px;
}

.edit-modal-save {
  flex: 1;
  padding: 13px;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: #fff;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
}

.edit-modal-cancel {
  flex: 1;
  padding: 13px;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--bg-elevated);
  color: var(--text-muted);
  font-size: 16px;
  font-weight: 500;
  cursor: pointer;
}

/* ============ Multi-Upload Dialog ============ */
.upload-dialog-overlay {
  position: fixed;
  inset: 0;
  z-index: 400;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: flex-end;
  animation: fadeIn 0.15s;
}

.upload-dialog {
  width: 100%;
  background: rgba(28, 28, 30, 0.98);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  padding: 20px 20px calc(20px + var(--safe-bottom));
  display: flex;
  flex-direction: column;
  gap: 12px;
  animation: slideUp 0.2s ease;
}

.upload-dialog-title {
  font-size: 17px;
  font-weight: 600;
  text-align: center;
}

.upload-dialog-files {
  font-size: 13px;
  color: var(--text-muted);
  display: flex;
  flex-direction: column;
  gap: 2px;
  max-height: 100px;
  overflow-y: auto;
}

.upload-dialog-options {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.upload-dialog-option {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  border: 0.5px solid var(--border);
  background: var(--bg-elevated);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.upload-dialog-option.selected {
  border-color: var(--accent);
  background: rgba(10, 132, 255, 0.1);
}

.upload-dialog-option input[type="radio"] {
  accent-color: var(--accent);
}

.upload-dialog-option-label {
  font-size: 15px;
  font-weight: 500;
}

.upload-dialog-option-desc {
  font-size: 12px;
  color: var(--text-muted);
}

.upload-dialog-btn {
  padding: 13px;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: #fff;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

/* ============ Chat Doc Links ============ */
.chat-doc-links {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.chat-doc-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  background: rgba(10, 132, 255, 0.15);
  border: 0.5px solid rgba(10, 132, 255, 0.3);
  border-radius: 100px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.15s;
}

.chat-doc-chip:active {
  background: rgba(10, 132, 255, 0.3);
}

/* ============ Utility ============ */
.hidden {
  display: none !important;
}

/* Scanner Modal */
.scanner-modal {
  position: fixed;
  inset: 0;
  background: #000;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.scanner-modal.hidden { display: none; }

.scanner-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  padding-top: max(12px, env(safe-area-inset-top));
  background: rgba(0,0,0,0.8);
  color: white;
}
.scanner-title { font-size: 17px; font-weight: 600; }
.scanner-btn-cancel {
  background: none; border: none; color: #ff3b30;
  font-size: 16px; cursor: pointer; padding: 4px 8px;
}
.scanner-btn-upload {
  background: #007aff; border: none; color: white;
  font-size: 16px; font-weight: 600; cursor: pointer;
  padding: 6px 16px; border-radius: 8px;
}

.scanner-canvas-wrap {
  flex: 1;
  position: relative;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #111;
  touch-action: none;
  user-select: none;
}
#scanner-canvas {
  max-width: 100%;
  max-height: 100%;
  display: block;
  touch-action: none;
}
.scanner-overlay {
  position: absolute;
  pointer-events: none;
  touch-action: none;
}
.scanner-overlay polygon {
  fill: rgba(0, 122, 255, 0.15);
  stroke: #007aff;
  stroke-width: 2;
}
.scanner-handle {
  fill: white;
  stroke: #007aff;
  stroke-width: 2;
  cursor: move;
  pointer-events: all;
}

.scanner-filters {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  padding-bottom: max(12px, env(safe-area-inset-bottom));
  background: rgba(0,0,0,0.9);
  overflow-x: auto;
  flex-shrink: 0;
}
.filter-btn {
  background: #333; border: none; color: white;
  font-size: 13px; padding: 6px 14px;
  border-radius: 16px; cursor: pointer; white-space: nowrap;
  flex-shrink: 0;
}
.filter-btn[data-active="true"] {
  background: #007aff;
}
.filter-slider-group {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  flex-shrink: 0;
}
.filter-slider-group label {
  color: #aaa; font-size: 11px;
}
.filter-slider-group input[type=range] {
  width: 80px;
  accent-color: #007aff;
}
.filter-shadow-placeholder { opacity: 0.4; }

.scanner-header-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}
.scanner-btn-add {
  background: #333;
  border: none;
  color: white;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  padding: 6px 14px;
  border-radius: 8px;
}
.scanner-pages {
  display: flex;
  gap: 8px;
  padding: 8px 12px;
  padding-bottom: max(8px, env(safe-area-inset-bottom));
  background: rgba(0,0,0,0.9);
  overflow-x: auto;
  flex-shrink: 0;
}
.scanner-pages.hidden { display: none; }
.scanner-page-thumb {
  position: relative;
  flex-shrink: 0;
  cursor: pointer;
  touch-action: none;
}
.scanner-page-thumb img {
  width: 48px;
  height: 64px;
  object-fit: cover;
  border-radius: 4px;
  border: 2px solid transparent;
}
.scanner-page-thumb.active img {
  border-color: #007aff;
}
.scanner-page-thumb .thumb-delete {
  position: absolute;
  top: -6px;
  right: -6px;
  width: 18px;
  height: 18px;
  background: #ff3b30;
  border: none;
  border-radius: 50%;
  color: white;
  font-size: 11px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}
.scanner-page-thumb.drag-over img {
  border-color: #ff9f0a;
  transform: scale(1.08);
  transition: transform 0.1s ease;
}

/* Camera Live View */
.camera-modal {
  position: fixed;
  inset: 0;
  background: #000;
  z-index: 1001;
  display: flex;
  flex-direction: column;
}
.camera-modal.hidden { display: none; }

.camera-viewport {
  flex: 1;
  position: relative;
  overflow: hidden;
  background: #000;
}
#camera-video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.camera-guide-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}
.camera-guide-frame {
  width: 75%;
  aspect-ratio: 3/4;
  border: 2px solid rgba(255, 255, 255, 0.8);
  border-radius: 8px;
  box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.35);
  position: relative;
}
.camera-guide-frame::before,
.camera-guide-frame::after {
  content: '';
  position: absolute;
  width: 24px;
  height: 24px;
  border-color: #007aff;
  border-style: solid;
}
.camera-guide-frame::before {
  top: -2px; left: -2px;
  border-width: 3px 0 0 3px;
  border-radius: 6px 0 0 0;
}
.camera-guide-frame::after {
  bottom: -2px; right: -2px;
  border-width: 0 3px 3px 0;
  border-radius: 0 0 6px 0;
}
.camera-hint {
  position: absolute;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  color: white;
  font-size: 13px;
  background: rgba(0, 0, 0, 0.5);
  padding: 6px 14px;
  border-radius: 20px;
  pointer-events: none;
  white-space: nowrap;
}

.rename-prompt {
  font-size: 14px;
  color: var(--text-primary, #fff);
}

.rename-prompt-input-row {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}

.rename-input {
  flex: 1;
  padding: 6px 10px;
  border-radius: 8px;
  border: 1px solid rgba(255,255,255,0.2);
  background: rgba(255,255,255,0.1);
  color: inherit;
  font-size: 14px;
}

.rename-confirm-btn {
  padding: 6px 14px;
  border-radius: 8px;
  border: none;
  background: var(--accent, #4f8ef7);
  color: #fff;
  font-size: 14px;
  cursor: pointer;
}

.rename-confirm-btn:disabled {
  opacity: 0.5;
  cursor: default;
}
