:root {
  --bg: #0f1117; --surface: #1a1d27; --surface2: #242736;
  --border: #2e3144; --text: #e4e6f0; --text2: #8b8fa3;
  --accent: #6c5ce7; --green: #00b894; --orange: #fdcb6e;
  --red: #e17055; --blue: #74b9ff; --purple: #a29bfe;
}
body.light {
  --bg: #f0f2f5; --surface: #ffffff; --surface2: #f5f6fa;
  --border: #dfe1e6; --text: #1a1d27; --text2: #6b7280;
  --accent: #6c5ce7; --green: #00a882; --orange: #e6a817;
  --red: #d04a38; --blue: #3b8bdb; --purple: #7c6dd8;
}
* { margin: 0; padding: 0; box-sizing: border-box; }
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; background: var(--bg); color: var(--text); min-height: 100vh; }

/* Login */
.login-overlay { position: fixed; inset: 0; background: var(--bg); z-index: 200; display: flex; justify-content: center; align-items: center; }
.login-box { background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 40px; width: 360px; max-width: 90vw; text-align: center; }
.login-box h1 { font-size: 22px; margin-bottom: 8px; }
.login-box p { font-size: 13px; color: var(--text2); margin-bottom: 24px; }
.login-box input { width: 100%; background: var(--surface2); border: 1px solid var(--border); color: var(--text); padding: 12px 14px; border-radius: 8px; font-size: 14px; margin-bottom: 12px; outline: none; }
.login-box input:focus { border-color: var(--accent); }
.login-box .login-btn { width: 100%; padding: 12px; background: var(--accent); color: #fff; border: none; border-radius: 8px; font-size: 14px; font-weight: 600; cursor: pointer; transition: background .2s; }
.login-box .login-btn:hover { background: #5a4bd1; }
.login-error { color: var(--red); font-size: 13px; margin-bottom: 12px; min-height: 18px; }

/* Header */
.header { background: var(--surface); border-bottom: 1px solid var(--border); padding: 16px 24px; display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 12px; }
.header h1 { font-size: 18px; font-weight: 600; }
.header h1 span { color: var(--text2); font-weight: 400; font-size: 14px; margin-left: 12px; }
.sync-badge { display: inline-flex; align-items: center; gap: 6px; padding: 4px 12px; border-radius: 20px; font-size: 12px; }
.sync-ok { background: rgba(0,184,148,.15); color: var(--green); }
.sync-off { background: rgba(139,143,163,.15); color: var(--text2); }
.header-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.header-actions input { background: var(--surface2); border: 1px solid var(--border); color: var(--text); padding: 8px 12px; border-radius: 8px; font-size: 13px; width: 160px; }
.btn { padding: 8px 16px; border-radius: 8px; border: none; cursor: pointer; font-size: 13px; font-weight: 500; transition: all .2s; display: inline-flex; align-items: center; gap: 6px; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: #5a4bd1; }
.btn-outline { background: transparent; border: 1px solid var(--border); color: var(--text2); }
.btn-outline:hover { border-color: var(--accent); color: var(--text); }
.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-danger { background: rgba(225,112,85,.15); color: var(--red); }
.btn-danger:hover { background: rgba(225,112,85,.25); }
.btn-icon { background: transparent; border: 1px solid var(--border); color: var(--text2); padding: 8px; border-radius: 8px; cursor: pointer; font-size: 16px; line-height: 1; transition: all .2s; }
.btn-icon:hover { border-color: var(--accent); color: var(--text); }

/* User info bar */
.user-bar { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text2); }
.user-bar .user-level { padding: 2px 8px; border-radius: 10px; font-size: 11px; font-weight: 600; }
.level-1 { background: rgba(116,185,255,.15); color: var(--blue); }
.level-2 { background: rgba(253,203,110,.15); color: var(--orange); }
.level-3 { background: rgba(225,112,85,.15); color: var(--red); }

/* Date navigation */
.date-nav { display: flex; align-items: center; gap: 8px; }
.date-nav button { background: var(--surface2); border: 1px solid var(--border); color: var(--text); padding: 6px 10px; border-radius: 6px; cursor: pointer; font-size: 14px; }
.date-nav button:hover { border-color: var(--accent); }
.date-nav input[type="date"] { background: var(--surface2); border: 1px solid var(--border); color: var(--text); padding: 6px 10px; border-radius: 6px; font-size: 13px; cursor: pointer; }

/* Layout */
.main { display: flex; gap: 0; height: calc(100vh - 100px); }
.content { flex: 1; overflow-y: auto; padding: 24px; }
.sidebar { width: 300px; background: var(--surface); border-left: 1px solid var(--border); display: flex; flex-direction: column; flex-shrink: 0; order: 2; transition: width .2s; }
.sidebar.minimized { width: 46px; overflow: hidden; }
.sidebar.minimized .worker-list, .sidebar.minimized .add-form, .sidebar.minimized .sidebar-header > div { display: none; }
.sidebar.minimized .sidebar-header h2 { display: none; }
body.sidebar-mini .sites-grid { grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
.sidebar-header { padding: 16px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; }
.sidebar-header h2 { font-size: 14px; font-weight: 600; color: var(--text2); text-transform: uppercase; letter-spacing: .5px; }
.worker-list { flex: 1; overflow-y: auto; padding: 8px; max-height: calc(100vh - 180px); }

/* Worker card */
.worker-card { background: var(--surface2); border: 1px solid var(--border); border-radius: 10px; padding: 10px 14px; margin-bottom: 6px; cursor: grab; transition: all .2s; display: flex; align-items: center; justify-content: space-between; }
.worker-card.no-drag { cursor: default; }
.worker-card:active { cursor: grabbing; }
.worker-card.no-drag:active { cursor: default; }
.worker-card:hover { border-color: var(--accent); }
.worker-card.dragging { opacity: .5; transform: scale(.95); }
.worker-card .name { font-size: 14px; font-weight: 500; }
.worker-card .status-dot { width: 8px; height: 8px; border-radius: 50%; }
.worker-card .actions { display: flex; gap: 4px; }
.worker-card .actions button { background: none; border: none; color: var(--text2); cursor: pointer; font-size: 16px; padding: 2px 4px; border-radius: 4px; }
.worker-card .actions button:hover { color: var(--red); background: rgba(225,112,85,.1); }
.status-present .status-dot { background: var(--green); }
.status-late .status-dot { background: var(--orange); }
.status-absent .status-dot { background: var(--red); }
.status-leave .status-dot { background: var(--blue); }
.status-unassigned .status-dot { background: var(--text2); }
.worker-card.status-border-present { outline: 2px dashed var(--green); outline-offset: 1px; }
.worker-card.status-border-late { outline: 2px dashed #f0c040; outline-offset: 1px; }
.worker-card.status-border-absent { outline: 2px dashed var(--red); outline-offset: 1px; }
.worker-card.status-border-leave { outline: 2px dashed var(--blue); outline-offset: 1px; }

/* Sections */
.section-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.section-header h2 { font-size: 16px; font-weight: 600; }
.section-toggle { display: flex; align-items: center; gap: 8px; }
.toggle-btn { background: transparent; border: 1px solid var(--border); color: var(--text2); padding: 4px 10px; border-radius: 6px; cursor: pointer; font-size: 12px; transition: all .2s; }
.toggle-btn:hover { border-color: var(--accent); color: var(--text); }
.expand-btn { background: transparent; border: 1px solid var(--border); color: var(--text2); padding: 4px 10px; border-radius: 6px; cursor: pointer; font-size: 12px; transition: all .2s; }
.expand-btn:hover { border-color: var(--accent); color: var(--text); }
.section-content.collapsed { display: none; }

/* Sites */
.sites-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 16px; margin-bottom: 24px; }
.site-zone { background: var(--surface); border: 2px dashed var(--border); border-radius: 14px; min-height: 120px; transition: all .2s; position: relative; }
.site-zone.locked { border-color: var(--orange); border-style: solid; }
.site-zone.drag-over { border-color: var(--accent); background: rgba(108,92,231,.08); }
.site-header { padding: 14px 16px 8px; display: flex; justify-content: space-between; align-items: center; }
.site-header h3 { font-size: 15px; font-weight: 600; display: flex; align-items: center; gap: 6px; }
.site-header .count { background: var(--surface2); padding: 2px 10px; border-radius: 12px; font-size: 12px; color: var(--text2); }
.lock-badge { font-size: 11px; padding: 1px 6px; border-radius: 4px; background: rgba(253,203,110,.2); color: var(--orange); font-weight: 600; }
.site-workers { padding: 8px 12px 12px; display: flex; flex-wrap: wrap; gap: 8px; min-height: 40px; max-height: 200px; overflow-y: auto; }
.site-worker-chip { background: var(--surface2); border: 1px solid var(--border); border-radius: 8px; padding: 6px 12px; font-size: 13px; cursor: grab; display: flex; align-items: center; gap: 8px; transition: all .15s; }
.site-worker-chip.no-drag { cursor: default; }
.site-worker-chip:hover { border-color: var(--accent); }
.site-worker-chip.status-border-present { outline: 2px dashed var(--green); outline-offset: 1px; }
.site-worker-chip.status-border-late { outline: 2px dashed #f0c040; outline-offset: 1px; }
.site-worker-chip.status-border-absent { outline: 2px dashed var(--red); outline-offset: 1px; }
.site-worker-chip.status-border-leave { outline: 2px dashed var(--blue); outline-offset: 1px; }
.site-worker-chip .remove-from-site { cursor: pointer; color: var(--text2); font-size: 14px; }
.site-worker-chip .remove-from-site:hover { color: var(--red); }

/* Status zones */
.status-zones { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 24px; }
.status-zone { background: var(--surface); border: 2px dashed var(--border); border-radius: 12px; padding: 12px; min-height: 80px; text-align: center; transition: all .2s; }
.status-zone.drag-over { border-color: var(--accent); background: rgba(108,92,231,.08); }
.status-zone h4 { font-size: 13px; text-transform: uppercase; letter-spacing: .5px; margin-bottom: 8px; }
.status-zone.zone-present h4 { color: var(--green); }
.status-zone.zone-late h4 { color: var(--orange); }
.status-zone.zone-absent h4 { color: var(--red); }
.status-zone.zone-leave h4 { color: var(--blue); }
.zone-chips { max-height: 200px; overflow-y: auto; }

/* Summary */
.summary { background: var(--surface); border-radius: 12px; padding: 16px 20px; display: flex; gap: 24px; align-items: center; flex-wrap: wrap; margin-bottom: 16px; }
.summary .stat { display: flex; align-items: center; gap: 8px; }
.summary .stat .num { font-size: 24px; font-weight: 700; }
.summary .stat .label { font-size: 12px; color: var(--text2); }

/* History */
.history { background: var(--surface); border-radius: 12px; padding: 16px 20px; }
.history-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.history h3 { font-size: 14px; color: var(--text2); }
.history-list { max-height: 250px; overflow-y: auto; }
.history-item { font-size: 13px; color: var(--text2); padding: 4px 0; border-bottom: 1px solid var(--border); }
.history-item:last-child { border: none; }
.history-item .time { color: var(--purple); margin-right: 8px; }

/* Add forms */
.add-form { padding: 12px; border-top: 1px solid var(--border); display: flex; gap: 6px; }
.add-form input { flex: 1; background: var(--surface2); border: 1px solid var(--border); color: var(--text); padding: 8px 10px; border-radius: 8px; font-size: 13px; }

/* Modal */
.modal-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.6); z-index: 100; justify-content: center; align-items: center; }
.modal-overlay.show { display: flex; }
.modal { background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 24px; width: 480px; max-width: 90vw; max-height: 85vh; overflow-y: auto; }
.modal h2 { margin-bottom: 16px; font-size: 18px; }
.modal label { display: block; font-size: 13px; color: var(--text2); margin-bottom: 4px; }
.modal input, .modal select { width: 100%; background: var(--surface2); border: 1px solid var(--border); color: var(--text); padding: 10px 12px; border-radius: 8px; font-size: 13px; margin-bottom: 12px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }

/* Full view modal */
.fullview-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.7); z-index: 90; justify-content: center; align-items: center; }
.fullview-overlay.show { display: flex; }
.fullview { background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 24px; width: 700px; max-width: 95vw; max-height: 85vh; overflow-y: auto; }
.fullview h2 { margin-bottom: 16px; font-size: 18px; display: flex; justify-content: space-between; align-items: center; }
.fullview .close-btn { background: none; border: none; color: var(--text2); font-size: 24px; cursor: pointer; }
.fullview .close-btn:hover { color: var(--text); }
.fullview .fv-item { padding: 8px 12px; border-bottom: 1px solid var(--border); font-size: 14px; display: flex; align-items: center; gap: 10px; }
.fullview .fv-item:last-child { border: none; }

/* User mgmt table */
.user-table { width: 100%; border-collapse: collapse; margin-top: 12px; }
.user-table th, .user-table td { padding: 8px 12px; text-align: left; border-bottom: 1px solid var(--border); font-size: 13px; }
.user-table th { color: var(--text2); font-weight: 600; text-transform: uppercase; font-size: 11px; letter-spacing: .5px; }

/* Note input */
.note-input { background: var(--surface2); border: 1px solid var(--border); color: var(--text); padding: 4px 8px; border-radius: 6px; font-size: 12px; width: 100px; }

/* Unified Toast */
.zy-toast { position: fixed; top: 20px; left: 50%; transform: translateX(-50%); padding: 12px 24px; border-radius: 10px; font-size: 14px; font-weight: 500; z-index: 320; pointer-events: auto; box-shadow: 0 4px 20px rgba(0,0,0,.4); display: flex; align-items: center; gap: 10px; max-width: 90vw; text-align: center; line-height: 1.5; animation: zyToastIn .3s ease; }
.zy-toast-error { background: rgba(225,112,85,.95); color: #fff; }
.zy-toast-warning { background: rgba(255,165,0,.95); color: #000; }
.zy-toast-success { background: rgba(0,184,148,.95); color: #fff; }
.zy-toast-info { background: var(--surface); color: var(--text); border: 1px solid var(--border); }
.zy-toast .zy-toast-close { background: rgba(255,255,255,.2); border: none; color: inherit; padding: 2px 10px; border-radius: 4px; cursor: pointer; font-size: 12px; font-weight: 600; flex-shrink: 0; }
.zy-toast-warning .zy-toast-close { background: rgba(0,0,0,.15); }
@keyframes zyToastIn { from { opacity: 0; transform: translateX(-50%) translateY(-10px); } to { opacity: 1; transform: translateX(-50%) translateY(0); } }
.zy-toast.zy-toast-out { animation: zyToastOut .4s ease forwards; }
@keyframes zyToastOut { to { opacity: 0; transform: translateX(-50%) translateY(-10px); } }

/* Unified Confirm Modal */
.zy-confirm-overlay { display: flex; position: fixed; inset: 0; background: rgba(0,0,0,.6); z-index: 400; justify-content: center; align-items: center; animation: zyFadeIn .2s ease; }
.zy-confirm { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 24px; width: 420px; max-width: 90vw; box-shadow: 0 8px 32px rgba(0,0,0,.5); }
.zy-confirm-msg { font-size: 14px; line-height: 1.6; color: var(--text); white-space: pre-line; margin-bottom: 20px; }
.zy-confirm-actions { display: flex; justify-content: flex-end; gap: 8px; }
.zy-confirm-btn { padding: 8px 20px; border-radius: 8px; border: none; cursor: pointer; font-size: 13px; font-weight: 600; transition: all .2s; }
.zy-confirm-cancel { background: var(--surface2); border: 1px solid var(--border); color: var(--text2); }
.zy-confirm-cancel:hover { border-color: var(--accent); color: var(--text); }
.zy-confirm-ok { background: var(--accent); color: #fff; }
.zy-confirm-ok:hover { background: #5a4bd1; }
.zy-confirm-ok.danger { background: var(--red); }
.zy-confirm-ok.danger:hover { background: #c0392b; }
@keyframes zyFadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes importPulse { 0%,100% { opacity:1; box-shadow:0 0 0 0 rgba(231,76,60,0.5); } 50% { opacity:0.9; box-shadow:0 0 12px 4px rgba(231,76,60,0.3); } }

/* Legacy overrides */
.toast-error { display: none !important; }
.save-warning { display: none !important; }

/* Scrollbar */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text2); }

/* Responsive */
/* Global Workers Panel */
.global-workers-panel {
  position: fixed; top: 0; right: -420px; width: 400px; height: 100vh;
  background: var(--surface); border-left: 1px solid var(--border);
  z-index: 150; transition: right .3s ease; display: flex; flex-direction: column;
  box-shadow: -4px 0 24px rgba(0,0,0,0.3);
}
.global-workers-panel.active { right: 0; }
.global-workers-inner { display: flex; flex-direction: column; height: 100%; }

@media (max-width: 768px) {
  .main { flex-direction: column; }
  .sidebar { width: 100%; height: auto; max-height: 250px; order: 0; border-left: none; border-bottom: 1px solid var(--border); }
  .status-zones { grid-template-columns: repeat(2, 1fr); }
  .sites-grid { grid-template-columns: 1fr; }
  .header-actions { flex-wrap: wrap; }
  .header-actions input { width: 120px; }
  .global-workers-panel { width: 100%; right: -100%; }
}
