:root {
  --bg: #0f1115;
  --bg-panel: #161922;
  --bg-panel-2: #1d212c;
  --border: #2a2f3c;
  --text: #e8eaf0;
  --text-dim: #8b91a5;
  --accent: #4f8cff;
  --accent-hover: #3d78e8;
  --danger: #e5484d;
  --success: #2fb56a;
  --radius: 10px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.hidden { display: none !important; }

/* --- Login --- */
#login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

.login-card {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 40px;
  width: 340px;
}

.login-card h1 {
  font-size: 20px;
  margin: 0 0 4px;
}

.login-card p.subtitle {
  color: var(--text-dim);
  font-size: 13px;
  margin: 0 0 24px;
}

/* --- Layout app --- */
#app-screen {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 220px;
  background: var(--bg-panel);
  border-right: 1px solid var(--border);
  padding: 20px 14px;
  display: flex;
  flex-direction: column;
}

.sidebar .brand {
  font-weight: 700;
  font-size: 16px;
  margin-bottom: 24px;
  padding: 0 6px;
}

.sidebar .brand span { color: var(--accent); }

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 8px;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 14px;
  margin-bottom: 4px;
}

.nav-item:hover { background: var(--bg-panel-2); color: var(--text); }
.nav-item.active { background: var(--accent); color: white; }

.sidebar .user-box {
  margin-top: auto;
  border-top: 1px solid var(--border);
  padding-top: 14px;
  font-size: 12px;
  color: var(--text-dim);
}

.sidebar .user-box .name { color: var(--text); font-weight: 600; font-size: 13px; }

main {
  flex: 1;
  padding: 28px 36px;
  overflow-y: auto;
}

.view-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.view-header h2 { margin: 0; font-size: 20px; }

/* --- Buttons --- */
button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  border-radius: 8px;
  padding: 9px 16px;
  font-size: 13px;
  font-weight: 600;
  transition: background 0.15s;
}

.btn-primary { background: var(--accent); color: white; }
.btn-primary:hover { background: var(--accent-hover); }

.btn-secondary { background: var(--bg-panel-2); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: #262b38; }

.btn-danger { background: transparent; color: var(--danger); border: 1px solid rgba(229,72,77,0.4); }
.btn-danger:hover { background: rgba(229,72,77,0.1); }

.btn-icon { background: transparent; padding: 6px 8px; color: var(--text-dim); }
.btn-icon:hover { color: var(--text); }

.btn-row { display: flex; gap: 8px; }

/* --- Inputs --- */
input, select {
  width: 100%;
  background: var(--bg-panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 13px;
  font-family: inherit;
  margin-bottom: 14px;
}

input:focus, select:focus { outline: 1px solid var(--accent); }

label { font-size: 12px; color: var(--text-dim); display: block; margin-bottom: 6px; }

.error-msg {
  color: var(--danger);
  font-size: 13px;
  margin-bottom: 12px;
  min-height: 16px;
}

/* --- Cards / grid --- */
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 14px;
}

.sheet-card {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  cursor: pointer;
  transition: border-color 0.15s;
}

.sheet-card:hover { border-color: var(--accent); }

.sheet-card .sheet-name { font-weight: 600; margin-bottom: 6px; word-break: break-word; }
.sheet-card .sheet-meta { font-size: 12px; color: var(--text-dim); margin-bottom: 12px; }

/* --- Table (admin) --- */
table { width: 100%; border-collapse: collapse; background: var(--bg-panel); border-radius: var(--radius); overflow: hidden; }
th, td { text-align: left; padding: 10px 14px; font-size: 13px; border-bottom: 1px solid var(--border); }
th { color: var(--text-dim); font-weight: 600; font-size: 12px; text-transform: uppercase; }
tr:last-child td { border-bottom: none; }

.badge { display: inline-block; padding: 3px 9px; border-radius: 999px; font-size: 11px; font-weight: 600; }
.badge-admin { background: rgba(79,140,255,0.15); color: var(--accent); }
.badge-user { background: rgba(139,145,165,0.15); color: var(--text-dim); }

/* --- Modal --- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.6);
  display: flex; align-items: center; justify-content: center; z-index: 100;
}
.modal {
  background: var(--bg-panel); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 28px; width: 380px;
}
.modal h3 { margin-top: 0; }

/* --- Editor --- */
#editor-view { display: flex; flex-direction: column; height: calc(100vh - 56px); }
#spreadsheet-container { flex: 1; overflow: auto; margin-top: 14px; }

.editor-toolbar { display: flex; align-items: center; justify-content: space-between; }
.save-status { font-size: 12px; color: var(--text-dim); }
