/* Layout feature bucket. Consider moving or importing css/dashboard.css here once migrated. */

/* Theme variables: Light */
:root[data-theme="light"] {
  color-scheme: light;
  --primary: #1a3e0a;
  --primary-dark: #183703;
  --accent: #2e7d32;
  --accent-light: rgba(46, 125, 50, 0.1);
  --bg: #f5f5f5;
  --card-bg: #ffffff;
  --card-hover: #f8f9fa;
  --muted-bg: #e9ecef;
  --text: #212121;
  --text-primary: #212121;
  --text-secondary: #666666;
  --border-color: #e2e8f0;
  --button-bg: #f8f9fa;
  --input-bg: #ffffff;
  --input-border: #e2e8f0;
  --success: #2e7d32;
  --warning: #ff9800;
  --danger: #f44336;
  --info: #2196f3;
  --shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06);
  --card-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

/* Baseline: wrappers rendered as grid contents */
#historyTimersRow { display: contents; }

/* Theme variables: Dark */
:root[data-theme="dark"] {
  color-scheme: dark;
  --primary: #1a3e0a;
  --primary-dark: #183703;
  --accent: #2e7d32;
  --accent-light: rgba(46, 125, 50, 0.1);
  --bg: #0a0f08;
  --card-bg: #11190e;
  --card-hover: #1a2612;
  --muted-bg: #121418;
  --text: #e0e0e0;
  --text-primary: #e0e0e0;
  --text-secondary: #a0a0a0;
  --border-color: rgba(24, 55, 3, 0.3);
  --input-bg: #121418;
  --input-border: #2b3036;
  --success: #2e7d32;
  --warning: #ff9800;
  --danger: #f44336;
  --info: #2196f3;
  --shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06);
  --card-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
  --button-bg: #edf2f7;
  --button-hover: #e2e8f0;
  --button-text: #2d3748;
}

/* Default theme (dark) when data-theme is not set */
:root:not([data-theme]) {
  font-size: 13px;
  color-scheme: dark;
  --primary: #1a3d07;
  --primary-hover: #2a530a;
  --primary-light: rgba(26, 61, 7, 0.06);
  --accent: #27ae60;
  --accent-hover: #2ecc71;
  --accent-light: rgba(39, 174, 96, 0.1);
  --success: #2ecc71;
  --success-hover: #3fe380;
  --danger: #e74c3c;
  --warning: #f39c12;
  --info: #3498db;
  --bg: #0d0f0c;
  --card-bg: #161a15;
  --border-color: #2a2f28;
  --text: #f8f9f7;
  --text-secondary: #b8c2b0;
  --text-muted: #6b7565;
  --shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
  --transition-fast: 0.15s ease;
  --transition-normal: 0.3s ease;
  --transition-slow: 0.5s ease;
  --border-radius: 8px;
  --transition: all 0.2s ease;
}

/* Base html/body setup */
html, body { height: 100%; margin: 0; padding: 0; overflow-x: hidden; }
* { box-sizing:border-box; margin:0; padding:0; -webkit-user-select: none; -ms-user-select: none; user-select: none; outline: none !important; }
body {
  font-family: 'Poppins', sans-serif;
  background: var(--bg);
  color: var(--text);
  padding: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  cursor: default;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
}

/* Improve touch behavior */
html { -webkit-text-size-adjust: 100%; }
body { touch-action: manipulation; }

/* Watermark backgrounds per theme */
:root[data-theme="dark"] body { position: relative; }
:root[data-theme="dark"] body::before {
  content: '';
  position: fixed; inset: 0;
  background-image: url('https://i.gyazo.com/c3ab77fa3d47e1f8162091246ad4261e.png');
  background-repeat: repeat;
  background-position: 0 0;
  background-size: clamp(90px, 12vmin, 180px);
  opacity: 0.04; pointer-events: none; z-index: 0;
}
:root[data-theme="dark"] header { position: relative; z-index: 3; }
:root[data-theme="dark"] .main-content { position: relative; z-index: 1; }

:root[data-theme="light"] body { position: relative; }
:root[data-theme="light"] body::before {
  content: '';
  position: fixed; inset: 0;
  background-image: url('https://i.gyazo.com/ec95dd28ee87b4c417b7643b267195cb.png');
  background-repeat: repeat;
  background-position: 0 0;
  background-size: clamp(110px, 14vmin, 220px);
  filter: none; opacity: 0.16; pointer-events: none; z-index: 0;
}
:root[data-theme="light"] header { position: relative; z-index: 3; }
:root[data-theme="light"] .main-content { position: relative; z-index: 1; }

/* Focus outline suppression (feature components re-enable where needed) */
*:focus { outline: none !important; box-shadow: none !important; }

/* Clickable element touch improvements */
button, [onclick], .location-btn { -webkit-tap-highlight-color: transparent; -webkit-user-select: none; -webkit-touch-callout: none; user-select: none; }

/* Global form controls */
button, select, input, textarea { width: 100%; padding: 10px; border-radius: 8px; border: none; font-size: 14px; margin-top: 10px; }
input, textarea, select { background: var(--input-bg); color: var(--text); border: 1px solid var(--input-border); -webkit-user-select: text; user-select: text; -webkit-touch-callout: default; touch-action: manipulation; }
button { background: var(--success); color: #fff; cursor: pointer; }
button.secondary { background: #3a3f47; }
button.danger, .btn-danger { background: var(--danger) !important; color: #fff !important; }
.btn-accent { background: var(--accent) !important; color: #fff !important; border: 1px solid var(--accent) !important; }

/* Small utility classes */
.row-between-end { display:flex; justify-content: space-between; align-items:flex-end; width:100%; }
.row-center-8 { display:flex; align-items:center; gap:8px; }
.row-between-center { display:flex; justify-content: space-between; align-items:center; }
.row-wrap-8 { display:flex; flex-wrap: wrap; gap: 8px; }
.row-end-8 { display:flex; gap:8px; justify-content:flex-end; }
.mt-4 { margin-top: 4px !important; }
.mt-10 { margin-top: 10px !important; }
.mt-6 { margin-top: 6px !important; }
.pt-12 { padding-top: 12px !important; }
.border-top { border-top: 1px solid var(--border-color) !important; }
.mt-16 { margin-top: 16px !important; }
.mb-20 { margin-bottom: 20px !important; }
.mt-auto { margin-top: auto !important; }
.mb-6 { margin-bottom: 6px !important; }
.w-full { width: 100% !important; }
.nowrap { flex-wrap: nowrap !important; }
.max-w-220 { max-width: 220px !important; }
.mb-12 { margin-bottom: 12px !important; }
.text-center { text-align: center !important; }
.text-right { text-align: right !important; }
.panel-soft { background: rgba(255, 187, 77, .04); padding: 12px; border-radius: 8px; }
.panel-card { background: var(--card-hover); padding: 10px; border-radius: 6px; border: 1px solid var(--border-color); }
/* Additional utility classes */
.hidden { display: none; }
.text-success { color: var(--success) !important; }
.text-secondary { color: var(--text-secondary) !important; }
.text-danger { color: var(--danger) !important; }
.username-badge { color: var(--accent); font-weight: 600; font-size: 0.9rem; text-shadow: 0 0 8px rgba(46, 125, 50, 0.3); padding: 0 10px; border-radius: 6px; background: rgba(46, 125, 50, 0.1); border: 1px solid var(--border-color); display: inline-flex; align-items: center; height: 32px; margin: 0; box-sizing: border-box; line-height: 1; }
.gap-8 { gap: 8px !important; }
.gap-10 { gap: 10px !important; }
.gap-12 { gap: 12px !important; }
.mt-8 { margin-top: 8px !important; }
.grid-2 { display: grid !important; grid-template-columns: 1fr 1fr !important; }
.grid-1-100 { display: grid !important; grid-template-columns: 1fr 100px !important; }
.grid-1-auto { display: grid !important; grid-template-columns: 1fr auto !important; }
.items-center { align-items: center !important; }
.mb-8 { margin-bottom: 8px !important; }
.flex-1 { flex: 1 1 0 !important; }
.min-w-0 { min-width: 0 !important; }
.truncate { white-space: nowrap !important; overflow: hidden !important; text-overflow: ellipsis !important; }
.btn-slim { padding: 6px 8px !important; font-size: 0.8rem !important; line-height: 1.2 !important; }
.max-h-300 { max-height: 300px !important; }
.max-h-380 { max-height: 380px !important; }
.min-h-240 { min-height: 240px !important; }
.overflow-auto { overflow: auto !important; }
.p-10 { padding: 10px !important; }
.flex-col { display: flex !important; flex-direction: column !important; }
.py-20 { padding-top: 20px !important; padding-bottom: 20px !important; }
.py-30 { padding-top: 30px !important; padding-bottom: 30px !important; }
.fs-09 { font-size: 0.9rem !important; }
.fs-08 { font-size: 0.8rem !important; }
.fs-085 { font-size: 0.85rem !important; }

/* Container and header */
.container { max-width: 1200px; margin: 0 auto; padding: 16px; min-height: calc(100vh - 40px); display: flex; flex-direction: column; box-sizing: border-box; }
header { text-align:center; margin-bottom:20px; padding-bottom:6px; border-bottom:3px solid var(--accent) }
h1 { color:var(--accent); letter-spacing:2px; margin-bottom:6px; font-size: 1.8rem; }
.subtitle { color:var(--text-secondary); margin-bottom:10px }
.data-info { display: inline-flex; align-items: center; gap: 5px; padding: 5px 8px; border-radius: 4px; background: rgba(255, 119, 0, 0.06); color: var(--text-secondary); font-size: 0.8rem; margin-top: 3px; }
.version-badge { display: inline-flex; align-items: center; font-weight: 600; font-size: 0.85rem; color: var(--text-secondary); background: transparent; border: none; border-radius: 999px; padding: 2px 8px; line-height: 1.2; }

/* Grid layout for dashboard */
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 14px; margin: 10px 0; flex: 1; min-height: 0; align-items: stretch; align-content: start; }

/* Card base */
.card { background: var(--card-bg); border-radius: 8px; padding: 14px; border: 1px solid var(--border-color); box-shadow: 0 2px 6px rgba(0,0,0,0.03); transition: all var(--transition-normal); position: relative; overflow: hidden; height: 100%; box-sizing: border-box; display: flex; flex-direction: column; }
.card::before { content: ''; position: absolute; top: 0; left: 0; width: 100%; height: 3px; background: var(--accent); transform: scaleX(0); transform-origin: left; transition: transform var(--transition-normal); opacity: 0.8; }
.card:hover { transform: translateY(-2px); box-shadow: 0 4px 12px rgba(0,0,0,0.08); border-color: var(--border-color); }
.card:focus-within { z-index: 5; overflow: visible; }
.card:hover::before { transform: scaleX(1); }
.card h2 { color: var(--accent); display:flex; align-items:center; gap:8px }

/* Draggable panels */
.draggable-panel { cursor: move; }
.draggable-panel.dragging { opacity: 0.75; box-shadow: 0 8px 24px rgba(0,0,0,0.4); }
.drag-handle { position:absolute; top:6px; left:6px; width:22px; height:22px; display:flex; align-items:center; justify-content:center; border-radius:4px; background: var(--card-hover); color: var(--text-secondary); cursor: move; z-index: 2; }
.drag-handle:hover { background: var(--card-bg); color: var(--text); }
.drag-handle i { pointer-events: none; }

/* Generic info sections */
.quest-info { display:flex; justify-content:space-between; color:var(--text-secondary); margin-bottom:10px }
.progress-container { height:10px; background:var(--muted-bg); border-radius:6px; overflow:hidden; margin:10px 0 }
.progress-bar { height:100%; background: linear-gradient(90deg, var(--accent), #2ecc71); border-radius:4px; transition:width .3s; box-shadow: 0 0 10px rgba(39, 174, 96, 0.4); }
.last-saved { background: var(--card-bg); border: 1px solid var(--border-color); border-radius: 6px; padding: 10px; margin-top: 12px; font-size: 0.85rem; color: var(--text-secondary); }

/* Server Reset Banner and info */
.server-reset-banner { background: var(--card-bg); border-radius: 6px; }
.server-reset-banner::before { content: ''; position: absolute; top: 0; left: 0; width: 4px; height: 100%; background: var(--accent); }
.server-status { color: inherit; text-decoration: none; cursor: default; }
.server-status:hover { text-decoration: none; }
#serverResetBanner { background: var(--card-bg); border: 1px solid var(--border-color); border-radius: 8px; padding: 16px; margin-bottom: 20px; box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1); transition: background-color 0.3s ease, border-color 0.3s ease; }
.server-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; flex-wrap: wrap; gap: 14px; }
.server-header h2 { margin: 0 0 4px 0; font-size: 1.25rem; color: var(--text-primary); }
.reset-schedule { display: flex; align-items: center; color: var(--text-secondary); font-size: 0.85rem; background: var(--card-hover); padding: 8px 12px; border-radius: 6px; border: 1px solid var(--border-color); margin: 8px 0 0 0; display: inline-flex; }
.reset-schedule i { margin-right: 8px; color: var(--accent); font-size: 0.95rem; }
.server-info { display: flex; flex-wrap: nowrap; gap: 24px; background: var(--card-hover); padding: 14px 18px; border-radius: 8px; border: 1px solid var(--border-color); margin: 0; }
.info-block { text-align: center; min-width: 100px; padding: 4px 8px; }
.info-label { display: block; font-size: 0.7rem; color: var(--text-secondary); margin-bottom: 4px; text-transform: uppercase; letter-spacing: 0.5px; font-weight: 600; }
.status-online { color: var(--accent); font-weight: 600; }
.current-time { font-family: 'Poppins', sans-serif; font-weight: 600; color: var(--accent); font-size: 1.1rem; letter-spacing: 0.5px; }
.info-divider { width: 1px; background: var(--border-color); margin: 0 4px; }
.countdown { font-family: 'Poppins', sans-serif; font-weight: 700; font-size: 1.4rem; color: var(--text); letter-spacing: 0.5px; transition: all var(--transition-normal); display: inline-block; line-height: 1.2; }
.next-reset { color: var(--accent); font-weight: 600; font-size: 0.95rem; }
.time-note { color: var(--text-secondary); font-size: 0.8rem; opacity: 0.8; }

/* Reset timers layout */
.reset-timers { display: flex; gap: 12px; margin: 16px 0 12px 0; }
.reset-timer { flex: 1; background: var(--card-bg); border: 1px solid var(--border-color); border-radius: 6px; padding: 12px; text-align: center; transition: all 0.3s ease; position: relative; overflow: hidden; }
.reset-timer::before { content: ''; position: absolute; top: 0; left: 0; width: 3px; height: 100%; background: var(--accent); transform: scaleY(0); transform-origin: top; transition: transform var(--transition-normal); opacity: 0.8; }
.reset-timer.active { background: rgba(46, 125, 50, 0.1); border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.reset-timer.active .countdown { color: var(--accent); text-shadow: 0 0 10px rgba(39, 174, 96, 0.3); }
.reset-timer:hover { transform: translateY(-2px); box-shadow: 0 4px 12px rgba(0,0,0,0.06); border-color: var(--accent); }
.reset-label { font-size: 0.85rem; color: var(--text-secondary); margin-bottom: 6px; transition: color 0.3s ease; }
.countdown::after { content: ''; position: absolute; bottom: -4px; left: 0; width: 100%; height: 2px; background: var(--accent); transform: scaleX(0); transition: transform var(--transition-normal); }
.reset-timer:hover .countdown::after { transform: scaleX(1); }

/* Light theme tweaks for server reset */
:root[data-theme="light"] #serverResetBanner { background: linear-gradient(145deg, #f8f9fa, #e9ecef); border-color: #dee2e6; }
.dashboard-compact #serverResetBanner .server-header h2 { font-size: 1.75rem !important; }
:root[data-theme="light"] .reset-schedule, :root[data-theme="light"] .reset-schedule * { color: #666666 !important; }
:root[data-theme="dark"] .reset-schedule, :root[data-theme="dark"] .reset-schedule * { color: #a0a0a0 !important; }

/* Override: Server Reset heading size (desktop/tablet) */
#serverResetBanner .server-header h2 { font-size: 1.75rem !important; line-height: 1.2; }
#serverResetTitle { font-size: 1.75rem !important; line-height: 1.2; }

/* Notifications */
.notification { position: fixed; right: 20px; bottom: 20px; background: var(--success); color: #fff; padding: 12px 16px; border-radius: 8px; box-shadow: 0 6px 18px rgba(0,0,0,.3); opacity: 0; transform: translateY(20px); transition: all 0.3s ease-in-out; max-width: 320px; z-index: 1000; display: flex; align-items: center; gap: 10px; overflow: hidden; }
.notification::before { content: ''; display: inline-block; width: 20px; height: 20px; background-size: contain; background-repeat: no-repeat; background-position: center; flex-shrink: 0; }
.notification.success { background-color: #28a745; border-left: 4px solid #218838; }
.notification.success::before { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='white'%3E%3Cpath d='M9 16.17L4.83 12l-1.42 1.41L9 19 21 7l-1.41-1.41L9 16.17z'/%3E%3C/svg%3E"); }
.notification.error { background-color: #dc3545; border-left: 4px solid #c82333; }
.notification.error::before { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='white'%3E%3Cpath d='M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm1 15h-2v-2h2v2zm0-4h-2V7h2v6z'/%3E%3C/svg%3E"); }
.notification.info { background-color: #17a2b8; border-left: 4px solid #138496; }
.notification.info::before { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='white'%3E%3Cpath d='M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm1 15h-2v-6h2v6zm0-8h-2V7h2v2z'/%3E%3C/svg%3E"); }
.notification.show { opacity: 1; transform: translateY(0); transition: opacity 0.3s ease-in-out, transform 0.3s ease-in-out; }
.notification:not(.show) { pointer-events: none; transition: opacity 0.3s ease-in-out 0.1s, transform 0.3s ease-in-out 0.1s; }

/* Presence chip */
.presence-chip { display: inline-flex; align-items: center; gap: 6px; height: 32px; padding: 0 10px; background: var(--card-hover); color: var(--text-secondary); border: 1px solid var(--border-color); border-radius: 6px; font-weight: 600; font-size: 0.9rem; box-shadow: var(--card-shadow); user-select: none; line-height: 1; box-sizing: border-box; }
.presence-chip i { font-size: 0.95em; opacity: 0.9; vertical-align: middle; line-height: 1; }
.presence-chip #presenceCount { min-width: 1ch; text-align: right; }
@media (max-width: 480px) {
  .presence-chip { height: 26px; padding: 0 8px; font-size: 0.85rem; }
}

/* User menu */
.user-menu { position: relative; display: flex; align-items: center; height: 32px; }
.user-menu-btn { display: inline-flex; align-items: center; justify-content: center; height: 32px; padding: 0 10px; gap: 8px; background: var(--card-hover); color: var(--text-secondary); border: 1px solid var(--border-color); border-radius: 6px; cursor: pointer; box-sizing: border-box; line-height: 1; font-size: 0.9rem; margin: 0; box-shadow: var(--card-shadow); -webkit-appearance: none; appearance: none; font-weight: 600; }
.user-menu-btn span { line-height: 1; display: inline-block; }
.user-menu-btn i { font-size: 0.95em; vertical-align: middle; line-height: 1; }
.user-menu-panel { position: absolute; right: 0; top: calc(100% + 6px); min-width: 200px; background: var(--card-bg); border: 1px solid var(--border-color); border-radius: 8px; box-shadow: var(--shadow); padding: 6px; display: none; z-index: 20; }
.user-menu-panel.open { display: block; }
.user-menu-item { width: 100%; display: flex; align-items: center; justify-content: flex-start; gap: 10px; padding: 8px 10px; border-radius: 6px; background: transparent; color: var(--text); border: none; text-align: left; cursor: pointer; }
.user-menu-item:hover { background: var(--card-hover); }
.user-menu-item i { font-size: 0.95rem; color: var(--text-secondary); }
.user-menu-item.danger { color: var(--danger); }
.server-status { color: inherit; text-decoration: none; cursor: default; }
.server-status:hover { text-decoration: none; }
.status-offline { color: var(--danger); font-weight: 600; }

/* Theme toggle button */
.theme-toggle { background: var(--card-bg); border: 1px solid var(--border-color); border-radius: 20px; width: 40px; height: 40px; display: flex; align-items: center; justify-content: center; cursor: pointer; transition: all 0.2s ease; color: var(--text); box-shadow: var(--shadow); }
.theme-toggle:hover { background: var(--primary); color: white; transform: translateY(-1px); box-shadow: 0 2px 5px rgba(0, 0, 0, 0.15); }
/* Theme toggle icon style */
.theme-toggle i { font-size: 20px; color: var(--text); transition: transform 0.3s ease; }

/* Very small phones portrait: hide presence chip */
@media (max-width: 360px) and (orientation: portrait) {
  .presence-chip { display: none; }
}

/* Core-only layout: show only essential panels */
body.show-core-only .grid > .card:not(.core-panel) { display: none; }
body.show-core-only .grid > #historyTimersRow { display: none; }
/* Reorder cards in core-only mode */
body.show-core-only .grid { display: flex; flex-direction: column; }

/* Tablet tweaks */
@media (max-width: 1024px) {
  .container { padding: 12px; }
}

/* Phone portrait tweaks (generic up to 768px) */
@media (max-width: 768px) {
  /* Force two-column row to stack */
  #historyTimersRow { grid-template-columns: 1fr !important; gap: 12px; }
  .grid { grid-template-columns: 1fr; grid-template-areas: none; flex: 1 !important; }
  .card { height: auto !important; overflow: visible; }
  /* Ensure wrapper stays transparent so its children remain grid items */
  #historyTimersRow { display: contents !important; }
  /* Server info wraps nicely */
  .server-info { flex-wrap: wrap; gap: 12px; }
  .server-info .info-divider { display: none; }
  .server-info .info-block { flex: 1 1 calc(50% - 12px); min-width: 0; }
}
