/* ==========================================================================
   itemDB - Modern Industrial & Tactile Dark Theme
   ========================================================================== */

:root {
  --bg-primary: #0f172a;       /* Slate 900 */
  --bg-surface: #1e293b;       /* Slate 800 */
  --bg-surface-elevated: #334155; /* Slate 700 */
  --border-color: #334155;
  --border-focus: #38bdf8;
  
  --text-main: #f8fafc;        /* Slate 50 */
  --text-muted: #94a3b8;       /* Slate 400 */
  --text-sub: #64748b;         /* Slate 500 */

  /* Parity Branding */
  --color-item: #38bdf8;       /* Sky 400 - Even ID 物品 */
  --color-item-bg: rgba(56, 189, 248, 0.12);
  --color-location: #c084fc;   /* Purple 400 - Odd ID 場所 */
  --color-location-bg: rgba(192, 132, 252, 0.12);

  --color-primary: #2563eb;    /* Blue 600 */
  --color-primary-hover: #1d4ed8;
  --color-success: #10b981;    /* Emerald 500 */
  --color-warning: #f59e0b;    /* Amber 500 */
  --color-danger: #ef4444;     /* Red 500 */

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.5);

  --font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

body {
  background-color: var(--bg-primary);
  color: var(--text-main);
  font-family: var(--font-family);
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Container */
.app-container {
  max-width: 500px;
  width: 100%;
  margin: 0 auto;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  padding: 0 16px 24px;
}

/* Header */
.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 0 12px;
  border-bottom: 1px solid var(--border-color);
  margin-bottom: 16px;
}

.logo-section {
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.app-title {
  font-size: 1.4rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  background: linear-gradient(135deg, #38bdf8, #818cf8);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.app-subtitle {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-family: var(--font-mono);
}

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

.icon-btn {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  width: 38px;
  height: 38px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 1.1rem;
  transition: all 0.15s ease;
}

.icon-btn:hover, .icon-btn:active {
  background: var(--bg-surface-elevated);
  border-color: var(--border-focus);
}

/* Scanner Viewport */
.scanner-wrapper {
  position: relative;
  width: 100%;
  border-radius: var(--radius-lg);
  overflow: hidden;
  background: #000;
  aspect-ratio: 1 / 1;
  border: 2px solid var(--border-color);
  box-shadow: var(--shadow-md);
}

.scanner-viewport {
  width: 100% !important;
  height: 100% !important;
}

.scanner-viewport video {
  width: 100% !important;
  height: 100% !important;
  object-fit: cover !important;
}

/* Scanner Frame Overlay */
.scanner-guide {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

.guide-frame {
  width: 70%;
  height: 70%;
  position: relative;
}

.corner {
  position: absolute;
  width: 24px;
  height: 24px;
  border-color: var(--border-focus);
  border-style: solid;
}

.corner.tl { top: 0; left: 0; border-width: 3px 0 0 3px; }
.corner.tr { top: 0; right: 0; border-width: 3px 3px 0 0; }
.corner.bl { bottom: 0; left: 0; border-width: 0 0 3px 3px; }
.corner.br { bottom: 0; right: 0; border-width: 0 3px 3px 0; }

.laser-line {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--border-focus), transparent);
  box-shadow: 0 0 8px var(--border-focus);
  animation: scan-pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
}

@keyframes scan-pulse {
  0% { top: 10%; opacity: 0.2; }
  50% { top: 90%; opacity: 1; }
  100% { top: 10%; opacity: 0.2; }
}

.guide-label {
  margin-top: 14px;
  font-size: 0.8rem;
  color: var(--text-muted);
  background: rgba(15, 23, 42, 0.75);
  padding: 4px 12px;
  border-radius: 20px;
  backdrop-filter: blur(4px);
}

/* Quick Actions */
.quick-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 14px;
}

.action-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 0.95rem;
  font-weight: 600;
  padding: 12px 14px;
}

/* Cards */
.card {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 18px;
  box-shadow: var(--shadow-sm);
}

.card-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}

.card-header.space-between {
  justify-content: space-between;
}

.warning-card {
  border-color: rgba(245, 158, 11, 0.4);
  background: rgba(245, 158, 11, 0.08);
  margin-bottom: 16px;
}

.warning-card .icon {
  font-size: 1.2rem;
  color: var(--color-warning);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 16px;
  border-radius: var(--radius-md);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: all 0.15s ease;
  text-decoration: none;
}

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

.btn-secondary {
  background: var(--bg-surface-elevated);
  color: var(--text-main);
  border: 1px solid var(--border-color);
}
.btn-secondary:hover { background: #475569; }

.btn-outline {
  background: transparent;
  color: var(--text-main);
  border: 1px solid var(--border-color);
}
.btn-outline:hover { background: var(--bg-surface); }

.btn-large {
  padding: 14px 20px;
  font-size: 1.05rem;
  width: 100%;
}

.btn-text {
  background: none;
  border: none;
  color: var(--color-item);
  font-size: 0.85rem;
  cursor: pointer;
  padding: 2px 6px;
}
.btn-text:hover { text-decoration: underline; }

.btn-link {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 0.9rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-bottom: 12px;
}
.btn-link:hover { color: var(--text-main); }

/* Badges */
.badge {
  display: inline-block;
  padding: 3px 8px;
  border-radius: var(--radius-sm);
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.04em;
}

.badge-small {
  padding: 2px 6px;
  font-size: 0.7rem;
}

.badge-even {
  background: var(--color-item-bg);
  color: var(--color-item);
  border: 1px solid rgba(56, 189, 248, 0.3);
}

.badge-odd {
  background: var(--color-location-bg);
  color: var(--color-location);
  border: 1px solid rgba(192, 132, 252, 0.3);
}

.id-tag {
  font-family: var(--font-mono);
  font-size: 0.85rem;
  color: var(--text-muted);
}

/* Detail View */
.detail-badge-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}

.detail-title {
  font-size: 1.4rem;
  font-weight: 800;
  word-break: break-all;
}

.property-grid {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

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

.prop-item.highlight-prop {
  background: rgba(15, 23, 42, 0.6);
  padding: 12px;
  border-radius: var(--radius-md);
  border-left: 3px solid var(--color-location);
}

.prop-label {
  font-size: 0.75rem;
  color: var(--text-sub);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 600;
}

.prop-val-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.location-val {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--color-location);
}

.prop-value {
  font-size: 0.95rem;
}

.action-buttons {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* Banner */
.banner {
  display: flex;
  gap: 12px;
  padding: 14px;
  border-radius: var(--radius-lg);
  margin-bottom: 12px;
}

.pending-banner {
  background: rgba(192, 132, 252, 0.15);
  border: 1px solid rgba(192, 132, 252, 0.4);
}

.batch-banner {
  background: rgba(56, 189, 248, 0.15);
  border: 1px solid rgba(56, 189, 248, 0.4);
}

.banner-icon {
  font-size: 1.5rem;
  line-height: 1;
}

.banner-body h4 {
  font-size: 1rem;
  font-weight: 700;
  margin-bottom: 2px;
}

.batch-controls {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

/* Item Lists */
.item-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.item-card-compact {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: transform 0.1s ease, border-color 0.1s ease;
}

.item-card-compact:hover {
  border-color: var(--border-focus);
  transform: translateX(2px);
}

.item-compact-info {
  display: flex;
  align-items: center;
  gap: 8px;
  overflow: hidden;
}

.item-compact-name {
  font-size: 0.95rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.item-compact-id {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--text-muted);
}

.history-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.history-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  background: rgba(15, 23, 42, 0.5);
  border-radius: var(--radius-sm);
  cursor: pointer;
}
.history-item:hover {
  background: var(--bg-surface-elevated);
}

.history-name {
  flex: 1;
  font-size: 0.9rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.history-id {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--text-sub);
}

/* Modals */
.modal-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 16px;
}

.modal-content {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  max-width: 440px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
}

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

.modal-body {
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.modal-footer {
  padding: 14px 20px;
  border-top: 1px solid var(--border-color);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

/* Forms */
.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-group label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
}

.form-input, .form-select {
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  padding: 10px 14px;
  border-radius: var(--radius-md);
  font-size: 0.95rem;
  font-family: inherit;
  outline: none;
}

.form-input:focus, .form-select:focus {
  border-color: var(--border-focus);
}

/* Keypad */
.keypad-display {
  width: 100%;
  padding: 14px;
  font-size: 1.5rem;
  font-family: var(--font-mono);
  text-align: center;
  background: var(--bg-primary);
  border: 2px solid var(--border-color);
  border-radius: var(--radius-md);
  color: var(--text-main);
  letter-spacing: 0.1em;
}

.keypad-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.num-key {
  height: 56px;
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  color: var(--text-main);
  font-size: 1.4rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.1s ease;
}

.num-key:active {
  background: var(--color-primary);
  transform: scale(0.96);
}

/* Toasts */
#toast-container {
  position: fixed;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: 90vw;
  width: 400px;
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 18px;
  border-radius: var(--radius-md);
  font-size: 0.9rem;
  font-weight: 600;
  box-shadow: var(--shadow-lg);
  pointer-events: auto;
}

.toast-info { background: #1e293b; border: 1px solid #475569; color: #fff; }
.toast-success { background: #064e3b; border: 1px solid #059669; color: #d1fae5; }
.toast-warning { background: #78350f; border: 1px solid #d97706; color: #fef3c7; }
.toast-error { background: #7f1d1d; border: 1px solid #dc2626; color: #fee2e2; }
.toast-added { background: #0c4a6e; border: 1px solid #0284c7; color: #e0f2fe; }
.toast-removed { background: #701a75; border: 1px solid #c026d3; color: #fae8ff; }

/* Global Loader */
.global-loader {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(15, 23, 42, 0.85);
  backdrop-filter: blur(6px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  z-index: 300;
}

.spinner {
  width: 44px;
  height: 44px;
  border: 4px solid var(--border-color);
  border-top-color: var(--border-focus);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* Helpers */
.hidden { display: none !important; }
.mt-2 { margin-top: 8px; }
.mt-3 { margin-top: 14px; }
.mt-4 { margin-top: 20px; }
.mb-2 { margin-bottom: 8px; }
.mb-3 { margin-bottom: 14px; }
.text-sub { font-size: 0.8rem; color: var(--text-sub); }
.text-muted { color: var(--text-muted); }
.text-success { color: var(--color-success); }
.text-warn { color: var(--color-warning); }
.text-danger { color: var(--color-danger); }
.empty-text { font-size: 0.85rem; color: var(--text-sub); text-align: center; padding: 12px 0; }
