:root {
  --bg: #f5f5f7; --bg-surface: #ffffff; --bg-hover: #f0f0f2;
  --text: #1d1d1f; --text-secondary: #86868b; --border: #d2d2d7;
  --border-focus: #22c55e; --accent: #22c55e; --accent-hover: #16a34a;
  --danger: #ff3b30; --danger-bg: #fff2f0; --danger-border: #ffccc7;
  --shadow-md: 0 4px 12px rgba(0,0,0,.1); --shadow-lg: 0 12px 40px rgba(0,0,0,.15);
  --radius: 10px; --radius-lg: 16px; --th-bg: #e5e5ea;
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  --transition: 0.2s ease; --icon-size: 48px;
}
:root[data-theme="dark"] {
  --bg: #1c1c1e; --bg-surface: #2c2c2e; --bg-hover: #3a3a3c;
  --text: #f5f5f7; --text-secondary: #aeaeb2; --border: #48484a;
  --border-focus: #4ade80; --accent: #4ade80; --accent-hover: #22c55e;
  --danger: #ff453a; --danger-bg: rgba(255,69,58,.12); --danger-border: rgba(255,69,58,.3);
  --th-bg: #3a3a3c; --shadow-md: 0 4px 12px rgba(0,0,0,.4); --shadow-lg: 0 12px 40px rgba(0,0,0,.5);
}

* { margin: 0; padding: 0; box-sizing: border-box; }
body { font-family: var(--font); font-size: 16px; background: var(--bg); color: var(--text); transition: background var(--transition), color var(--transition); }
#root { min-height: 100vh; }

input, textarea, select { font-family: var(--font); font-size: 15px; padding: 10px 14px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--bg-surface); color: var(--text); outline: none; width: 100%; transition: border-color var(--transition), box-shadow var(--transition); }
input:focus, textarea:focus, select:focus { border-color: var(--border-focus); box-shadow: 0 0 0 3px rgba(34,197,94,.12); }
input::placeholder { color: var(--text-secondary); }

button { font-family: var(--font); font-size: 15px; font-weight: 500; padding: 10px 20px; border: none; border-radius: var(--radius); background: var(--accent); color: #fff; cursor: pointer; transition: background var(--transition), transform var(--transition); }
button:hover { background: var(--accent-hover); } button:active { transform: scale(.98); } button:disabled { opacity: .5; cursor: not-allowed; }

.iconbar { position: fixed; left: 0; top: 0; bottom: 0; width: calc(var(--icon-size) + 8px); background: var(--bg-surface); border-right: 1px solid var(--border); display: flex; flex-direction: column; align-items: center; padding: calc(var(--icon-size) + 12px) 0 8px; gap: 4px; z-index: 200; overflow: hidden; transition: width var(--transition); }
.iconbar.closed { width: 0 !important; overflow: hidden; border: none !important; padding: 0 !important; margin: 0 !important; }
.iconbar button { width: var(--icon-size); height: var(--icon-size); display: flex; align-items: center; justify-content: center; border: none; border-radius: var(--radius); background: none; color: var(--text-secondary); font-size: calc(var(--icon-size) * .55); cursor: pointer; transition: background var(--transition), color var(--transition); flex-shrink: 0; line-height: 1; }
.iconbar button:hover { background: var(--bg-hover); color: var(--text); } .iconbar button.active { color: var(--accent); }
.iconbar-float { position: fixed; left: 4px; top: 8px; z-index: 999; width: var(--icon-size); height: var(--icon-size); display: flex; align-items: center; justify-content: center; border: none; border-radius: var(--radius); background: var(--bg-surface); color: var(--text-secondary); font-size: calc(var(--icon-size) * .55); cursor: pointer; box-shadow: var(--shadow-md); }
.iconbar-float:hover { background: var(--bg-hover); color: var(--text); }

.sidebar { position: fixed; left: calc(var(--icon-size) + 8px); top: 0; bottom: 0; width: 240px; background: var(--bg-surface); overflow-y: auto; border-right: 1px solid var(--border); transition: width var(--transition); }
.sidebar.closed { width: 0; overflow: hidden; border: none; }
.sidebar-item { display: flex; justify-content: space-between; align-items: center; padding: 6px 12px; cursor: pointer; font-size: 14px; } .sidebar-item:hover { background: var(--bg-hover); }

.view { position: fixed; left: calc(var(--icon-size) + 8px); top: 0; right: 0; bottom: 0; overflow: hidden; display: flex; flex-direction: column; }
.view-close { position: absolute; top: 6px; right: 10px; z-index: 10; width: 24px; height: 24px; padding: 0; font-size: 14px; background: var(--bg-hover); color: var(--text-secondary); border-radius: 4px; display: flex; align-items: center; justify-content: center; }
.view-close:hover { background: var(--danger-bg); color: var(--danger); }
.content-wrap { display: flex; flex-direction: column; height: 100%; } .content-wrap .table-scroll { flex: 1; }

.hidden{display:none!important}
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.15); display: flex; align-items: center; justify-content: center; z-index: 1000; }
.modal { background: var(--bg-surface); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg); padding: 36px; width: fit-content; max-width: 90vw; min-width: 320px; }
.modal h2 { font-size: 20px; font-weight: 600; margin-bottom: 24px; text-align: center; } .modal button { width: 100%; margin-top: 4px; }
.modal input { margin-bottom: 12px; } .modal input[type="password"] { margin-bottom: 16px; }
.modal-error { color: var(--danger); background: var(--danger-bg); border: 1px solid var(--danger-border); padding: 8px 12px; border-radius: var(--radius); font-size: 14px; margin-bottom: 16px; }

.edit-modal { min-width: 380px; padding: 28px; }
.edit-label { font-size: 14px; font-weight: 600; color: var(--text-secondary); margin-bottom: 12px; }
.edit-textarea { font-size: 15px; padding: 12px; border-radius: 8px; resize: vertical; margin-bottom: 16px; min-height: 100px; }
.edit-btns { display: flex; justify-content: flex-end; gap: 8px; } .edit-btns button { padding: 8px 20px; font-size: 14px; }
.edit-btns button:first-child { background: var(--bg-hover); color: var(--text); } .edit-btns button:first-child:hover { background: var(--border); }

.table-scroll { flex: 1; overflow: auto; } .table-scroll table { width: 100%; table-layout: fixed; border-collapse: collapse; }
.table-scroll th, .table-scroll td { padding: 6px 10px; border: 1px solid var(--border); font-size: 15px; white-space: nowrap; overflow: hidden; }
.table-scroll th { font-weight: 600; text-align: left; background: var(--th-bg); cursor: pointer; } .table-scroll td { cursor: pointer; }

.bottombar { display: flex; align-items: center; padding: 4px 10px; border-top: 1px solid var(--border); gap: 6px; font-size: 13px; color: var(--text-secondary); flex-shrink: 0; }
.bottombar input { width: 56px; font-size: 13px; padding: 2px 6px; text-align: center; }
.bottombar button { padding: 4px 12px; font-size: 13px; }

.where-popup { position: fixed; z-index: 2000; background: var(--bg-surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-lg); padding: 8px; display: flex; gap: 6px; align-items: center; }
.where-popup input { width: 200px; font-size: 13px; padding: 4px 8px; } .where-popup button { padding: 4px 12px; font-size: 13px; white-space: nowrap; }
.where-popup button:last-child { background: var(--bg-hover); color: var(--text); } .where-popup button:last-child:hover { background: var(--border); }

.email-compose { padding: 20px; overflow-y: auto; height: 100%; background: var(--bg); }
.email-fields { display: flex; flex-direction: column; gap: 12px; }
.email-row { display: flex; align-items: center; gap: 8px; } .email-row label { width: 56px; text-align: right; font-size: 14px; color: var(--text-secondary); flex-shrink: 0; }
.email-row input[type="text"] { width: auto; flex: 1; font-size: 14px; padding: 6px 8px; } .email-name { max-width: 160px; flex: none; }
.email-body { align-items: flex-start; } .email-body textarea { min-height: 200px; font-size: 14px; }
.email-actions { display: flex; align-items: center; gap: 12px; margin-top: 16px; padding-top: 12px; border-top: 1px solid var(--border); } .email-actions button { width: auto; }
.email-drop { flex: 1; border: 2px dashed var(--border); border-radius: var(--radius); padding: 6px 10px; min-height: 34px; transition: border-color var(--transition); } .email-drop.drag-over { border-color: var(--accent); }
.drop-hint { color: var(--text-secondary); font-size: 14px; } .drop-file { display: inline-block; padding: 4px 10px; margin: 3px; border-radius: 4px; background: var(--bg-hover); font-size: 13px; cursor: pointer; } .drop-file:hover { background: var(--danger-bg); color: var(--danger); }
.email-add { width: auto; padding: 4px 14px; font-size: 13px; background: var(--bg-hover); color: var(--text-secondary); font-weight: 400; } .email-add:hover { background: var(--border); color: var(--text); }
.email-remove { width: 28px; height: 28px; padding: 0; font-size: 16px; background: none; color: var(--text-secondary); flex-shrink: 0; display: flex; align-items: center; justify-content: center; } .email-remove:hover { background: var(--danger-bg); color: var(--danger); }
.send-ok { color: var(--accent); font-size: 14px; } .send-fail { color: var(--danger); font-size: 14px; }

.buffer-panel { padding: 20px; } .buffer-status { font-size: 16px; margin-bottom: 16px; padding: 12px; border-radius: var(--radius); background: var(--bg-surface); }
.buffer-on { color: var(--accent); font-weight: 600; } .buffer-off { color: var(--text-secondary); }
.buffer-actions { display: flex; gap: 10px; } .buffer-actions button { width: auto; }

.sql-panel { position: fixed; right: 0; width: 380px; height: 50%; border-left: 1px solid var(--border); background: var(--bg-surface); display: flex; flex-direction: column; z-index: 100; }
.sql-panel:nth-child(1) { top: 0; }
.sql-panel:nth-child(2) { top: 50%; }
.sql-panel-head { padding: 4px 10px; font-size: 12px; font-weight: 600; color: var(--text-secondary); border-bottom: 1px solid var(--border); background: var(--th-bg); display: flex; align-items: center; }
.sql-panel-body { flex: 1; padding: 6px 8px; font-size: 12px; font-family: monospace; white-space: pre-wrap; word-break: break-all; overflow-y: auto; resize: none; border: none; background: var(--bg); color: var(--text); outline: none; width: 100%; }

.theme-toggle, .logout-btn { position: fixed; right: 12px; z-index: 1001; border-radius: var(--radius); background: var(--bg-surface); box-shadow: var(--shadow-md); cursor: pointer; }
.theme-toggle { top: 12px; width: 36px; height: 36px; display: flex; align-items: center; justify-content: center; font-size: 16px; color: var(--text); } .theme-toggle:hover { background: var(--bg-hover); }
.logout-btn { top: 56px; padding: 6px 14px; font-size: 13px; color: var(--text-secondary); } .logout-btn:hover { background: var(--danger-bg); color: var(--danger); }
