body { font-family: 'Pretendard', sans-serif; background: #F5F5F7; color: #1D1D1F; height: 100vh; overflow: hidden; }
:root { --sheet-scale: 1; --sheet-max-width: 1200px; }
.sidebar { width: 320px; background: rgba(255, 255, 255, 0.8); backdrop-filter: blur(20px); border-right: 1px solid rgba(0,0,0,0.05); }
.apple-card { background: #FFFFFF; border-radius: 22px; box-shadow: 0 4px 24px rgba(0, 0, 0, 0.04); border: 1px solid rgba(0,0,0,0.02); transition: 0.3s; }
.nav-item { padding: 12px 16px; border-radius: 14px; cursor: pointer; transition: 0.2s; font-size: 14px; color: #48484A; display: flex; align-items: center; gap: 10px; }
.nav-item:hover { background: rgba(0,0,0,0.03); }
.nav-item.active { background: #0071E3; color: white; font-weight: 600; }
input, select, textarea { background: #F5F5F7 !important; border: 1px solid transparent !important; border-radius: 12px !important; padding: 10px !important; font-size: 13px !important; }
input:focus, textarea:focus { border-color: #0071E3 !important; background: white !important; outline: none; }
.tab-content { display: none; height: 100%; overflow-y: auto; padding: 40px; }
.tab-content.active { display: block; }
.chat-container { position: fixed; right: 20px; bottom: 20px; width: 400px; height: 600px; z-index: 1000; display: none; box-sizing: border-box; overflow: hidden; }
.chat-container.active { display: flex; }
.chat-messages { flex: 1; overflow-y: auto; padding: 20px; min-height: 0; }
.chat-input-row { align-items: stretch; }
#chat-input { height: 42px; line-height: normal; padding: 10px 12px; box-sizing: border-box; }
.message { padding: 12px 16px; border-radius: 18px; margin-bottom: 12px; max-width: 85%; }
.message.user { background: #0071E3; color: white; margin-left: auto; }
.message.ai { background: #F5F5F7; color: #1D1D1F; }
.chat-toggle { position: fixed; right: 30px; bottom: 30px; width: 60px; height: 60px; border-radius: 50%; background: linear-gradient(135deg, #0071E3, #00C6FF); color: white; display: flex; align-items: center; justify-content: center; cursor: pointer; box-shadow: 0 8px 32px rgba(0,113,227,0.3); z-index: 999; transition: 0.3s; }
.chat-toggle:hover { transform: scale(1.1); }
.chat-toggle.chat-open { display: none; }
.dm-toggle { position: fixed; right: 30px; bottom: 100px; width: 56px; height: 56px; border-radius: 50%; background: linear-gradient(135deg, #10B981, #34D399); color: white; display: flex; align-items: center; justify-content: center; cursor: pointer; box-shadow: 0 8px 32px rgba(16,185,129,0.3); z-index: 998; transition: 0.3s; }
.dm-toggle:hover { transform: scale(1.08); }
.dm-popup { position: fixed; right: 30px; bottom: 170px; width: 360px; max-height: 640px; background: white; border-radius: 20px; box-shadow: 0 12px 40px rgba(0,0,0,0.12); border: 1px solid rgba(0,0,0,0.05); z-index: 998; display: flex; flex-direction: column; overflow: hidden; opacity: 0; transform: translateY(16px) scale(0.98); pointer-events: none; transition: opacity 0.2s ease, transform 0.2s ease; }
.dm-popup.active { opacity: 1; transform: translateY(0) scale(1); pointer-events: auto; }
.dm-popup.hidden { display: none; }
.dm-header { padding: 14px 16px; border-bottom: 1px solid #F0F0F0; display: flex; align-items: center; justify-content: space-between; }
.dm-body { padding: 14px; display: flex; flex-direction: column; min-height: 0; }
.dm-input-row { align-items: stretch; }
#dm-input { height: 38px; line-height: normal; padding: 8px 12px; box-sizing: border-box; }
#dm-messages { flex: 1 1 auto; min-height: 120px; height: auto !important; }
.dm-request-modal { position: fixed; inset: 0; background: rgba(0,0,0,0.4); display: flex; align-items: center; justify-content: center; z-index: 10000; }
.dm-request-modal.hidden { display: none; }
.dm-request-card { background: white; border-radius: 16px; padding: 20px; width: 320px; box-shadow: 0 12px 40px rgba(0,0,0,0.2); }
.dm-share-card { background: #f9fafb; border: 1px solid #e5e7eb; padding: 10px 12px; border-radius: 12px; display: inline-flex; flex-direction: column; gap: 6px; }
.dm-share-card button { font-size: 12px; }
.dm-modal { position: fixed; inset: 0; background: rgba(0,0,0,0.5); display: flex; align-items: center; justify-content: center; z-index: 10000; }
.dm-modal-card { background: white; border-radius: 16px; padding: 20px; width: 360px; box-shadow: 0 12px 40px rgba(0,0,0,0.2); }
.dm-conversation-item { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.dm-conversation-meta { display: flex; flex-direction: column; gap: 2px; }
.dm-conversation-delete { color: #ef4444; font-size: 12px; }
.ocr-modal { position: fixed; inset: 0; background: rgba(0,0,0,0.55); z-index: 10000; display: flex; align-items: center; justify-content: center; padding: 24px; }
.ocr-card { background: white; border-radius: 18px; padding: 20px; width: min(900px, 95vw); max-height: 90vh; overflow: auto; }
.ocr-preview { position: relative; width: 100%; height: 420px; background: #0f172a; border-radius: 12px; overflow: hidden; display: flex; align-items: center; justify-content: center; }
.ocr-preview img { max-width: 100%; max-height: 100%; object-fit: contain; position: relative; z-index: 1; }
.ocr-bar { position: absolute; top: 0; bottom: 0; min-width: 80px; border: 2px dashed #60a5fa; background: rgba(96,165,250,0.15); cursor: grab; z-index: 2; }
.ocr-bar:active { cursor: grabbing; }
.ocr-handle { position: absolute; top: 0; bottom: 0; width: 10px; background: rgba(59,130,246,0.7); }
.ocr-handle.left { left: -6px; cursor: ew-resize; }
.ocr-handle.right { right: -6px; cursor: ew-resize; }
.sheet-card { transition: 0.3s; max-width: var(--sheet-max-width); margin: 0 auto; transform-origin: top center; zoom: var(--sheet-scale); }
.sheet-card > * { transform: none; }
.sheet-card:hover { transform: translateY(-4px); box-shadow: 0 12px 40px rgba(0,0,0,0.08); }
@supports not (zoom: 1) {
  .sheet-card { zoom: 1; }
  .sheet-card > * { transform: scale(var(--sheet-scale)); transform-origin: top center; }
}
table { width: 100%; border-collapse: collapse; }
th, td { border: 1px solid #F0F0F0; padding: 12px; text-align: left; }
th { background: #F9FAFB; font-weight: 600; color: #6B7280; font-size: 12px; text-transform: uppercase; }
.delete-btn { color: #EF4444; cursor: pointer; transition: 0.2s; }
.delete-btn:hover { color: #DC2626; transform: scale(1.1); }
.sheet-tab { padding: 8px 16px; border-radius: 10px; cursor: pointer; transition: 0.2s; font-size: 13px; font-weight: 600; color: #6B7280; }
.sheet-tab:hover { background: #F3F4F6; }
.sheet-tab.active { background: #0071E3; color: white; }
.sheets-grid { display: grid; grid-template-columns: repeat(3, minmax(320px, 1fr)); gap: 16px; }
.sheets-grid .sheet-card { margin: 0; }
.sheet-layout-active { background: #111827 !important; color: white !important; }
.sheet-layout-toggle { display: inline-flex; gap: 4px; padding: 4px; border-radius: 14px; border: 1px solid rgba(0,0,0,0.08); background: white; }
.sheet-layout-btn { display: inline-flex; align-items: center; gap: 6px; padding: 8px 12px; border-radius: 10px; font-size: 12px; font-weight: 700; color: #374151; }
.sheet-layout-btn i { font-size: 16px; }
.sheet-layout-btn:disabled { opacity: 0.45; cursor: not-allowed; }
.sheet-selection-status { font-size: 12px; font-weight: 700; color: #6B7280; padding: 8px 10px; border-radius: 12px; background: rgba(255,255,255,0.9); border: 1px solid rgba(15,23,42,0.08); }
.sheets-viewer { position: relative; }
#tab-sheets.sheet-free-mode.active { display: flex; flex-direction: column; gap: 16px; overflow: hidden; }
#tab-sheets.sheet-free-mode .sheets-viewer { flex: 1; min-height: 0; }
.sheets-free-viewport { position: relative; width: 100%; height: 100%; min-height: 60vh; background: linear-gradient(135deg, #f8fafc, #eef2f7); border-radius: 22px; border: 1px dashed rgba(15, 23, 42, 0.15); overflow: hidden; }
.sheets-free-stage { position: absolute; top: 0; left: 0; transform-origin: 0 0; }
.sheets-free-stage .sheet-card { position: absolute; margin: 0; max-width: var(--sheet-max-width); width: var(--sheet-max-width); zoom: 1; transform-origin: top left; cursor: grab; transition: none; will-change: transform; }
.sheets-free-stage .sheet-card > * { transform: none !important; }
.sheets-free-stage .sheet-card:hover { box-shadow: 0 12px 40px rgba(0,0,0,0.08); }
.sheets-free-stage .sheet-card.sheet-card-selected { box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.95), 0 14px 32px rgba(37, 99, 235, 0.16); }
.sheet-selection-box { position: absolute; pointer-events: none; z-index: 20; border-radius: 12px; border: 1.5px solid rgba(37, 99, 235, 0.85); background: rgba(37, 99, 235, 0.10); box-shadow: inset 0 0 0 1px rgba(255,255,255,0.35); }
.sheet-dragging { cursor: grabbing; }
.sheets-free-viewport.sheet-free-panning { cursor: grabbing; }
.history-select-wrap { position: relative; }
.history-select {
  width: 100%;
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  background: white;
  border: 2px solid #e5e7eb;
  border-radius: 14px;
  padding: 12px 44px 12px 14px;
  font-weight: 700;
  cursor: pointer;
  transition: border-color 0.2s ease, box-shadow 0.2s ease, background-color 0.2s ease;
}
.history-select:focus {
  outline: none;
  box-shadow: 0 0 0 3px rgba(0, 0, 0, 0.08);
}
.history-select-icon {
  position: absolute;
  right: 14px;
  top: 50%;
  transform: translateY(-50%);
  pointer-events: none;
  font-size: 20px;
  color: #6b7280;
}
.history-select-label { color: #4b5563; }
.history-select-label--siege { color: #7e22ce; }
.history-select-label--guildwar { color: #b91c1c; }
.history-select-label--totalwar { color: #b45309; }
.history-select-label--expedition { color: #be123c; }
.history-select-label--general { color: #047857; }
.history-select-label--ranking { color: #1d4ed8; }
.history-select--siege { border-color: #a855f7; background: #faf5ff; color: #7e22ce; }
.history-select--siege:focus { box-shadow: 0 0 0 3px rgba(168, 85, 247, 0.2); }
.history-select--guildwar { border-color: #ef4444; background: #fff1f2; color: #b91c1c; }
.history-select--guildwar:focus { box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.2); }
.history-select--totalwar { border-color: #f59e0b; background: #fffbeb; color: #b45309; }
.history-select--totalwar:focus { box-shadow: 0 0 0 3px rgba(245, 158, 11, 0.2); }
.history-select--expedition { border-color: #f43f5e; background: #fff1f2; color: #be123c; }
.history-select--expedition:focus { box-shadow: 0 0 0 3px rgba(244, 63, 94, 0.2); }
.history-select--general { border-color: #10b981; background: #ecfdf5; color: #047857; }
.history-select--general:focus { box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.2); }
.history-select--ranking { border-color: #3b82f6; background: #eff6ff; color: #1d4ed8; }
.history-select--ranking:focus { box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.2); }

/* Mobile UI */
.mobile-topbar { display: none; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 16px; position: sticky; top: 0; z-index: 40; background: rgba(245,245,247,0.9); backdrop-filter: blur(12px); border-bottom: 1px solid rgba(0,0,0,0.06); }
.mobile-menu-btn { width: 40px; height: 40px; border-radius: 12px; background: #111827; color: white; display: flex; align-items: center; justify-content: center; }
.mobile-brand { display: flex; flex-direction: column; gap: 2px; text-align: center; flex: 1; }
.mobile-title { font-size: 14px; font-weight: 800; color: #111827; }
.mobile-subtitle { font-size: 10px; color: #6b7280; }
.mobile-mode-btn { display: inline-flex; align-items: center; gap: 6px; padding: 8px 10px; font-size: 11px; font-weight: 700; color: #111827; background: #e2e8f0; border-radius: 10px; }
.mobile-nav { display: none; position: fixed; left: 50%; bottom: 16px; transform: translateX(-50%); z-index: 990; background: white; border: 1px solid rgba(0,0,0,0.08); box-shadow: 0 12px 32px rgba(0,0,0,0.12); border-radius: 999px; padding: 6px; gap: 6px; }
.mobile-nav-item { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; padding: 8px 10px; border-radius: 999px; font-size: 10px; font-weight: 700; color: #6b7280; min-width: 62px; }
.mobile-nav-item i { font-size: 18px; }
.mobile-nav-item.active { background: #111827; color: white; }
.mobile-drawer-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,0.45); z-index: 1000; display: none; }
.mobile-drawer-backdrop.active { display: block; }

body.mobile-mode #main-app { display: block; }
body.mobile-mode .sidebar { position: fixed; left: 0; top: 0; height: 100vh; width: min(85vw, 320px); transform: translateX(-100%); transition: transform 0.25s ease; z-index: 1001; display: block; }
body.mobile-mode .sidebar.mobile-drawer-open { transform: translateX(0); box-shadow: 12px 0 32px rgba(0,0,0,0.18); }
body.mobile-mode .mobile-topbar { display: flex; }
body.mobile-mode .mobile-nav { display: flex; }
body.mobile-mode .tab-content { padding: 18px 16px 120px; height: calc(100dvh - 140px); min-height: calc(100dvh - 140px); }
body.mobile-mode .sheets-grid { grid-template-columns: 1fr; }
body.mobile-mode { --sheet-scale: 1; --sheet-max-width: 100%; }
body.mobile-mode .sheet-card { max-width: 100%; width: 100%; zoom: 1; }
body.mobile-mode .chat-container { right: 12px; left: 12px; width: auto; height: min(70vh, 520px); bottom: 90px; }
body.mobile-mode .dm-popup { right: 12px; left: 12px; width: auto; bottom: 90px; max-height: 70vh; }
body.mobile-mode .chat-toggle { right: 16px; bottom: 16px; }
body.mobile-mode .dm-toggle { right: 88px; bottom: 16px; }
@media (max-width: 1400px) {
  .sheets-grid { grid-template-columns: repeat(2, minmax(320px, 1fr)); }
}
@media (max-width: 1024px) {
  .sheets-grid { grid-template-columns: 1fr; }
}
