@import url('https://fonts.googleapis.com/css2?family=DM+Sans:wght@400;500;600;700&family=Noto+Sans+TC:wght@400;500;700&display=swap');

:root {
  --bg-page: #FAFAF8;
  --bg-card: #FFFFFF;
  --bg-sidebar: #2D2B29;
  --bg-input: #F3F2EF;
  --bg-hover: #F0EEEA;
  --bg-header: #FFFFFF;
  --accent: #E8634A;
  --accent-hover: #D4523A;
  --accent-light: rgba(232,99,74,0.08);
  --accent-text: #FFFFFF;
  --text-primary: #2D2B29;
  --text-secondary: #6B6966;
  --text-muted: #9E9B97;
  --text-white: #FFFFFF;
  --border: #E5E3DF;
  --border-light: #EDEBE8;
  --success: #3EAF6E;
  --warning: #E8A84A;
  --danger: #D94848;
  --info: #4A8FE8;
  --radius: 10px;
  --radius-lg: 16px;
  --radius-sm: 6px;
  --shadow-sm: 0 1px 3px rgba(45,43,41,0.06);
  --shadow-md: 0 4px 12px rgba(45,43,41,0.08);
  --shadow-lg: 0 8px 30px rgba(45,43,41,0.12);
  --font: 'DM Sans', 'Noto Sans TC', -apple-system, sans-serif;
  --transition: 0.2s ease;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html { font-size: 16px; }
body { font-family: var(--font); background: var(--bg-page); color: var(--text-primary); line-height: 1.6; -webkit-font-smoothing: antialiased; }
a { color: var(--accent); text-decoration: none; }
button { cursor: pointer; font-family: inherit; }
input, select, textarea { font-family: inherit; font-size: 0.9rem; }
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #C9C6C2; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #A8A5A1; }

.login-page {
  min-height: 100vh;
  display: flex;
}
.login-brand {
  flex: 1;
  background: linear-gradient(145deg, #E8634A 0%, #D4523A 50%, #C2412E 100%);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  padding: 60px;
  color: #fff;
  position: relative;
  overflow: hidden;
}
.login-brand::before {
  content: '';
  position: absolute;
  top: -100px;
  right: -100px;
  width: 400px;
  height: 400px;
  border-radius: 50%;
  background: rgba(255,255,255,0.06);
}
.login-brand::after {
  content: '';
  position: absolute;
  bottom: -80px;
  left: -80px;
  width: 300px;
  height: 300px;
  border-radius: 50%;
  background: rgba(255,255,255,0.04);
}
.login-brand h1 { font-size: 2.4rem; font-weight: 700; margin-bottom: 12px; z-index: 1; }
.login-brand p { font-size: 1.1rem; opacity: 0.85; z-index: 1; max-width: 340px; text-align: center; }
.login-form-wrap {
  flex: 1;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 40px;
  background: var(--bg-page);
}
.login-form {
  width: 100%;
  max-width: 380px;
}
.login-form h2 { font-size: 1.6rem; font-weight: 700; margin-bottom: 8px; }
.login-form .subtitle { color: var(--text-secondary); margin-bottom: 32px; font-size: 0.95rem; }
.form-group { margin-bottom: 20px; }
.form-group label { display: block; font-size: 0.85rem; font-weight: 500; color: var(--text-secondary); margin-bottom: 6px; }
.form-group input {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  color: var(--text-primary);
  transition: var(--transition);
  outline: none;
}
.form-group input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-light); }
.btn-primary {
  width: 100%;
  padding: 13px;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: var(--accent-text);
  font-size: 1rem;
  font-weight: 600;
  transition: var(--transition);
}
.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:disabled { opacity: 0.6; cursor: not-allowed; }
.login-error { color: var(--danger); font-size: 0.85rem; margin-bottom: 16px; display: none; text-align: center; }

.app-layout { display: flex !important; flex-direction: column !important; height: 100vh; }
.app-layout.hidden { display: none !important; }
.app-header {
  height: 56px;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 20px;
  gap: 16px;
  flex-shrink: 0;
  box-shadow: var(--shadow-sm);
  z-index: 10;
}
.app-logo { font-size: 1.15rem; font-weight: 700; color: var(--accent); }
.app-header .doc-title { font-size: 0.95rem; color: var(--text-secondary); }
.header-spacer { flex: 1; }
.header-btn {
  padding: 7px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  color: var(--text-primary);
  font-size: 0.82rem;
  font-weight: 500;
  transition: var(--transition);
  display: flex;
  align-items: center;
  gap: 5px;
}
.header-btn:hover { background: var(--bg-hover); border-color: #ccc; }
.header-btn.accent { background: var(--accent); color: #fff; border-color: var(--accent); }
.header-btn.accent:hover { background: var(--accent-hover); }
.header-user { font-size: 0.85rem; color: var(--text-secondary); }
.header-user strong { color: var(--text-primary); }

.doc-list-page { max-width: 900px; margin: 0 auto; padding: 40px 20px; }
.doc-list-page h1 { font-size: 1.6rem; margin-bottom: 24px; }
.doc-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px; }
.doc-card {
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  padding: 20px;
  cursor: pointer;
  transition: var(--transition);
}
.doc-card:hover { box-shadow: var(--shadow-md); border-color: var(--accent); transform: translateY(-1px); }
.doc-card h3 { font-size: 1rem; margin-bottom: 6px; }
.doc-card .meta { font-size: 0.8rem; color: var(--text-muted); }

.sheet-tabs {
  display: flex;
  background: var(--bg-card);
  border-top: 1px solid var(--border);
  overflow-x: auto;
  flex-shrink: 0;
}
.sheet-tab {
  padding: 10px 20px;
  font-size: 0.82rem;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-weight: 500;
  white-space: nowrap;
  border-bottom: 2px solid transparent;
  transition: var(--transition);
}
.sheet-tab:hover { color: var(--text-primary); background: var(--bg-hover); }
.sheet-tab.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }
.del-sheet { margin-left: 6px; font-size: 0.7rem; color: var(--text-muted); cursor: pointer; opacity: 0.5; transition: var(--transition); }
.del-sheet:hover { color: var(--danger); opacity: 1; }

.spreadsheet-area {
  flex: 1;
  overflow: hidden;
  position: relative;
  min-height: 0;
}
.formula-cell { background: #F5F3EE !important; color: var(--text-secondary) !important; }

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 300px;
  color: var(--text-muted);
  font-size: 0.95rem;
}
.empty-state .icon { font-size: 3rem; margin-bottom: 12px; opacity: 0.4; }

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(45,43,41,0.4);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1000;
  display: none;
}
.modal-overlay.show { display: flex; }
.modal {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  padding: 28px;
  width: 90%;
  max-width: 440px;
  box-shadow: var(--shadow-lg);
}
.modal h3 { font-size: 1.2rem; margin-bottom: 20px; }
.modal .form-group { margin-bottom: 16px; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 20px; }
.btn-cancel {
  padding: 9px 18px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  color: var(--text-primary);
  font-weight: 500;
}
.btn-submit {
  padding: 9px 18px;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: #fff;
  font-weight: 600;
}
.btn-submit:hover { background: var(--accent-hover); }

.admin-layout { display: flex; height: 100vh; }
.admin-sidebar {
  width: 220px;
  background: var(--bg-sidebar);
  color: var(--text-white);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}
.admin-sidebar .logo { padding: 20px; font-size: 1.15rem; font-weight: 700; color: var(--accent); border-bottom: 1px solid rgba(255,255,255,0.08); }
.admin-nav { flex: 1; padding: 12px 0; }
.admin-nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 20px;
  color: rgba(255,255,255,0.65);
  font-size: 0.88rem;
  font-weight: 500;
  transition: var(--transition);
}
.admin-nav a:hover { color: #fff; background: rgba(255,255,255,0.06); }
.admin-nav a.active { color: var(--accent); background: rgba(232,99,74,0.1); }
.admin-sidebar .user-info { padding: 16px 20px; border-top: 1px solid rgba(255,255,255,0.08); font-size: 0.82rem; color: rgba(255,255,255,0.5); }
.admin-sidebar .logout-btn {
  display: block;
  padding: 10px 20px;
  color: rgba(255,255,255,0.5);
  font-size: 0.82rem;
  border: none;
  background: none;
  text-align: left;
  width: 100%;
  cursor: pointer;
}
.admin-sidebar .logout-btn:hover { color: #fff; background: rgba(239,68,68,0.15); }

.admin-main { flex: 1; overflow-y: auto; padding: 28px; background: var(--bg-page); }
.admin-main h1 { font-size: 1.5rem; margin-bottom: 20px; }

.data-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--bg-card);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}
.data-table th, .data-table td { padding: 11px 14px; text-align: left; font-size: 0.85rem; }
.data-table th { background: #F7F6F4; font-weight: 600; color: var(--text-secondary); border-bottom: 1px solid var(--border); }
.data-table td { border-bottom: 1px solid var(--border-light); }
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: var(--accent-light); }

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 0.75rem;
  font-weight: 600;
}
.badge.admin { background: rgba(232,99,74,0.1); color: var(--accent); }
.badge.client { background: rgba(74,143,232,0.1); color: var(--info); }
.badge.active { background: rgba(62,175,110,0.1); color: var(--success); }
.badge.disabled { background: rgba(158,155,151,0.1); color: var(--text-muted); }

.action-btn {
  padding: 5px 10px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--bg-card);
  font-size: 0.78rem;
  cursor: pointer;
  transition: var(--transition);
  margin-right: 4px;
}
.action-btn:hover { background: var(--bg-hover); }
.action-btn.danger { color: var(--danger); border-color: rgba(217,72,72,0.3); }
.action-btn.danger:hover { background: rgba(217,72,72,0.06); }

.toolbar { display: flex; gap: 10px; margin-bottom: 20px; flex-wrap: wrap; }

.upload-area {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 40px;
  text-align: center;
  cursor: pointer;
  transition: var(--transition);
  background: var(--bg-card);
  margin-bottom: 20px;
}
.upload-area:hover { border-color: var(--accent); background: var(--accent-light); }
.upload-area .icon { font-size: 2.5rem; margin-bottom: 10px; opacity: 0.4; }
.upload-area p { color: var(--text-secondary); font-size: 0.9rem; }

.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  padding: 12px 20px;
  border-radius: var(--radius-sm);
  font-size: 0.88rem;
  color: #fff;
  z-index: 2000;
  transform: translateY(80px);
  opacity: 0;
  transition: 0.3s ease;
}
.toast.show { transform: translateY(0); opacity: 1; }
.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }

.admin-editor-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
  flex-wrap: nowrap;
}
.admin-editor-title {
  margin: 0;
  font-size: 1.2rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.admin-title-mobile {
  display: none;
}

@media (max-width: 768px) {
  .login-brand { display: none; }
  .login-form-wrap { padding: 20px 16px; }
  .login-form h2 { font-size: 1.3rem; }

  .doc-list-page { padding: 16px 12px; }
  .doc-list-page h1 { font-size: 1.3rem; margin-bottom: 16px; }
  .doc-grid { grid-template-columns: 1fr; gap: 10px; }
  .doc-card { padding: 14px; }
  .doc-card h3 { font-size: 0.92rem; }

  .app-header { height: 48px; padding: 0 10px; gap: 8px; }
  .app-logo { font-size: 1rem; }
  .app-header .doc-title { font-size: 0.82rem; max-width: 120px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .header-btn { padding: 5px 8px; font-size: 0.75rem; }
  .header-user { font-size: 0.78rem; }

  .mobile-menu-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg-card);
    font-size: 1.1rem;
    cursor: pointer;
    flex-shrink: 0;
  }
  .mobile-toolbar-menu {
    position: fixed;
    top: 60px;
    right: 8px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: 0 6px 24px rgba(0,0,0,0.18);
    z-index: 9999;
    display: none;
    flex-direction: column;
    min-width: 160px;
    max-height: calc(100vh - 60px);
    overflow-y: auto;
  }
  .mobile-toolbar-menu.show { display: flex; }
  .mobile-toolbar-menu .header-btn {
    border: none;
    border-bottom: 1px solid var(--border-light);
    border-radius: 0;
    padding: 14px 18px;
    font-size: 0.92rem;
    justify-content: flex-start;
    width: 100%;
    text-align: left;
  }
  .mobile-toolbar-menu .header-btn:first-child { border-radius: var(--radius) var(--radius) 0 0; padding-top: 16px; }
  .mobile-toolbar-menu .header-btn:last-child { border-bottom: none; border-radius: 0 0 var(--radius) var(--radius); }

  .pc-toolbar-items { display: none !important; }

  .spreadsheet-area {
    -webkit-overflow-scrolling: touch;
    touch-action: auto;
  }

  .sheet-tabs {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 50;
    background: var(--bg-card);
    border-top: 1px solid var(--border);
    box-shadow: 0 -2px 8px rgba(0,0,0,0.06);
  }
  .sheet-tab { padding: 12px 18px; font-size: 0.92rem; }
  .app-layout { height: calc(100vh - 50px); height: calc(100dvh - 50px); }

  .toast {
    left: 12px;
    right: 12px;
    bottom: 16px;
    text-align: center;
    border-radius: var(--radius-sm);
  }

  .admin-sidebar {
    position: fixed;
    left: -260px;
    top: 0;
    bottom: 0;
    width: 240px;
    z-index: 200;
    transition: left 0.25s ease;
  }
  .admin-sidebar.open { left: 0; }
  .admin-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.35);
    z-index: 199;
  }
  .admin-overlay.show { display: block; }

  .admin-editor-toolbar {
    gap: 6px;
    margin-bottom: 0;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  .admin-editor-toolbar .header-btn {
    padding: 6px 10px;
    font-size: 0.8rem;
    white-space: nowrap;
    flex-shrink: 0;
  }
  .admin-title-pc { display: none !important; }
  .admin-title-mobile {
    display: block;
    font-size: 0.88rem;
    font-weight: 600;
    color: var(--text-primary);
    padding: 6px 0 10px;
    word-break: break-all;
    line-height: 1.4;
  }

  .admin-main { padding: 12px; }
  .admin-main h1 { font-size: 1.2rem; }
  .admin-mobile-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px;
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 50;
  }
  .admin-mobile-header .hamburger {
    width: 36px;
    height: 36px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg-card);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    cursor: pointer;
    flex-shrink: 0;
  }
  .data-table { font-size: 0.78rem; }
  .data-table th, .data-table td { padding: 8px 8px; }
  .toolbar { gap: 6px; }
}

@media (min-width: 769px) {
  .mobile-menu-toggle { display: none !important; }
  .mobile-toolbar-menu { display: none !important; }
  .admin-overlay { display: none !important; }
  .admin-mobile-header { display: none !important; }
}
