:root {
  --blue: #1a73e8;
  --blue-hover: #1765cc;
  --blue-soft: #e8f0fe;
  --blue-ink: #1967d2;
  --bg: #f8f9fa;
  --surface: #fff;
  --border: #dadce0;
  --border-strong: #bdc1c6;
  --text: #202124;
  --muted: #5f6368;
  --green: #1e8e3e;
  --red: #d93025;
  --red-soft: #fce8e6;
  --yellow: #f9ab00;
  --radius: 8px;
  --radius-sm: 4px;
  --shadow-1: 0 1px 2px rgba(60, 64, 67, 0.3), 0 1px 3px 1px rgba(60, 64, 67, 0.15);
  --shadow-2: 0 1px 3px rgba(60, 64, 67, 0.3), 0 4px 8px 3px rgba(60, 64, 67, 0.15);
  --font: "Google Sans", "Segoe UI", Roboto, system-ui, -apple-system, Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- top bar ---------- */
.topbar {
  height: 64px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
  font-size: 18px;
  font-weight: 500;
  padding: 8px;
  border-radius: var(--radius-sm);
  text-decoration: none;
}
.brand:hover { text-decoration: none; background: #f1f3f4; }
.brand svg { flex: none; }
.brand-sub { color: var(--muted); font-weight: 400; font-size: 13px; }

.topbar-spacer { flex: 1; }

.topbar-link {
  color: var(--muted);
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  font-size: 14px;
}
.topbar-link:hover { background: #f1f3f4; text-decoration: none; color: var(--text); }

.avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--blue);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 500;
  border: 0;
  cursor: pointer;
  text-transform: uppercase;
}
.avatar:hover { box-shadow: var(--shadow-1); }

.menu {
  position: absolute;
  top: 56px;
  right: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-2);
  min-width: 240px;
  padding: 8px 0;
  display: none;
  z-index: 30;
}
.menu.open { display: block; }
.menu-head { padding: 8px 16px 12px; border-bottom: 1px solid var(--border); }
.menu-head small { display: block; color: var(--muted); }
.menu button {
  width: 100%;
  text-align: left;
  background: none;
  border: 0;
  padding: 10px 16px;
  font: inherit;
  color: var(--text);
  cursor: pointer;
}
.menu button:hover { background: #f1f3f4; }

/* ---------- layout ---------- */
.page { max-width: 1160px; margin: 0 auto; padding: 32px 24px 64px; }

.hero {
  background: linear-gradient(135deg, #e8f0fe 0%, #ffffff 55%);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 48px;
  margin-bottom: 28px;
}
.hero h1 { font-size: 34px; line-height: 1.2; margin: 0 0 12px; font-weight: 500; letter-spacing: -0.2px; }
.hero p { margin: 0 0 24px; color: var(--muted); font-size: 16px; max-width: 640px; }
.hero-actions { display: flex; gap: 12px; flex-wrap: wrap; }

.section-title {
  font-size: 18px;
  font-weight: 500;
  margin: 32px 0 16px;
  color: var(--text);
}

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 16px;
}

.card {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 24px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  transition: box-shadow 0.15s ease, border-color 0.15s ease;
  color: inherit;
  text-decoration: none;
  min-height: 180px;
}
.card:hover { box-shadow: var(--shadow-1); border-color: var(--border-strong); text-decoration: none; }
.card-icon {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--blue-soft);
  color: var(--blue);
}
.card h3 { margin: 0; font-size: 16px; font-weight: 500; }
.card p { margin: 0; color: var(--muted); font-size: 13px; flex: 1; }
.card-foot { display: flex; align-items: center; gap: 8px; color: var(--blue); font-size: 13px; font-weight: 500; }
.badge {
  font-size: 11px;
  font-weight: 500;
  padding: 2px 8px;
  border-radius: 100px;
  background: #f1f3f4;
  color: var(--muted);
}
.badge.blue { background: var(--blue-soft); color: var(--blue-ink); }

/* ---------- buttons ---------- */
.btn {
  height: 36px;
  padding: 0 20px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font: inherit;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: transparent;
  color: var(--blue);
  white-space: nowrap;
}
.btn:hover { background: rgba(26, 115, 232, 0.06); }
.btn-primary { background: var(--blue); color: #fff; }
.btn-primary:hover { background: var(--blue-hover); }
.btn-outline { border-color: var(--border); color: var(--blue); background: var(--surface); }
.btn-outline:hover { background: #f8fbff; border-color: var(--border-strong); }
.btn-danger { color: var(--red); }
.btn-danger:hover { background: var(--red-soft); }
.btn[disabled] { opacity: 0.55; cursor: not-allowed; }
.btn-sm { height: 32px; padding: 0 14px; font-size: 13px; }

/* ---------- forms ---------- */
.field { position: relative; margin-top: 20px; }
.field input {
  width: 100%;
  height: 56px;
  padding: 20px 15px 6px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font: inherit;
  font-size: 15px;
  background: var(--surface);
  color: var(--text);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.field input:focus { border-color: var(--blue); box-shadow: inset 0 0 0 1px var(--blue); }
.field label {
  position: absolute;
  left: 15px;
  top: 17px;
  color: var(--muted);
  font-size: 15px;
  pointer-events: none;
  transition: all 0.12s ease;
  background: transparent;
}
.field input:focus + label,
.field input:not(:placeholder-shown) + label {
  top: 7px;
  font-size: 11px;
  color: var(--blue);
}
.field input:not(:focus):not(:placeholder-shown) + label { color: var(--muted); }

.form-error {
  margin-top: 16px;
  background: var(--red-soft);
  color: #a50e0e;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  display: none;
}
.form-error.show { display: block; }
.form-hint { color: var(--muted); font-size: 12px; margin-top: 8px; }

/* ---------- auth ---------- */
.auth-wrap {
  min-height: calc(100vh - 64px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px 16px;
}
.auth-card {
  width: 448px;
  max-width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 40px;
}
.auth-card h1 { font-size: 24px; margin: 0 0 8px; font-weight: 500; }
.auth-card .sub { color: var(--muted); margin: 0 0 8px; }
.auth-actions { display: flex; align-items: center; justify-content: space-between; margin-top: 28px; gap: 12px; }
.auth-foot { margin-top: 24px; font-size: 13px; color: var(--muted); }

/* ---------- app shell ---------- */
.shell { display: flex; min-height: calc(100vh - 64px); }
.rail {
  width: 240px;
  flex: none;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 12px 8px;
}
.rail a {
  display: flex;
  align-items: center;
  gap: 14px;
  height: 40px;
  padding: 0 16px;
  border-radius: 0 100px 100px 0;
  color: var(--text);
  font-size: 14px;
  text-decoration: none;
}
.rail a:hover { background: #f1f3f4; text-decoration: none; }
.rail a.active { background: var(--blue-soft); color: var(--blue-ink); font-weight: 500; }
.rail svg { flex: none; opacity: 0.75; }
.rail a.active svg { opacity: 1; }
.rail-sep { height: 1px; background: var(--border); margin: 12px 16px; }

.workspace { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  min-height: 56px;
  flex-wrap: wrap;
}
.crumbs { display: flex; align-items: center; gap: 4px; flex: 1; min-width: 0; overflow: hidden; }
.crumbs button {
  background: none;
  border: 0;
  font: inherit;
  color: var(--muted);
  cursor: pointer;
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  white-space: nowrap;
}
.crumbs button:hover { background: #f1f3f4; color: var(--text); }
.crumbs .sep { color: var(--muted); }
.crumbs .current { color: var(--text); font-weight: 500; cursor: default; }

/* ---------- table ---------- */
.table-wrap { padding: 0; overflow-x: auto; }
table.list { width: 100%; border-collapse: collapse; background: var(--surface); }
table.list th {
  text-align: left;
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
table.list td {
  padding: 0 16px;
  height: 52px;
  border-bottom: 1px solid #f1f3f4;
  font-size: 14px;
  vertical-align: middle;
}
table.list tr:hover td { background: #f8f9fa; }
.name-cell { display: flex; align-items: center; gap: 12px; min-width: 0; }
.name-cell .label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.name-cell .label.link { color: var(--blue); cursor: pointer; }
.name-cell .label.link:hover { text-decoration: underline; }
.icon-sq { width: 20px; height: 20px; flex: none; color: var(--muted); }
.row-actions { display: flex; gap: 4px; opacity: 0; transition: opacity 0.1s; }
tr:hover .row-actions, tr:focus-within .row-actions { opacity: 1; }
.icon-btn {
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.icon-btn:hover { background: #e8eaed; color: var(--text); }
.icon-btn.danger:hover { background: var(--red-soft); color: var(--red); }

.empty {
  padding: 64px 16px;
  text-align: center;
  color: var(--muted);
  background: var(--surface);
}
.empty h3 { color: var(--text); font-weight: 500; margin: 12px 0 4px; }

/* ---------- mail ---------- */
.mail-shell { flex: 1; display: flex; min-height: 0; height: calc(100vh - 64px - 56px); }
.mail-folders { width: 216px; flex: none; border-right: 1px solid var(--border); background: var(--surface); padding: 12px 8px; }
.mail-folders button {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  border: 0;
  background: none;
  font: inherit;
  color: var(--text);
  padding: 0 16px;
  height: 40px;
  border-radius: 0 100px 100px 0;
  cursor: pointer;
}
.mail-folders button:hover { background: #f1f3f4; }
.mail-folders button.active { background: var(--blue-soft); color: var(--blue-ink); font-weight: 500; }
.mail-list { width: 360px; flex: none; border-right: 1px solid var(--border); background: var(--surface); overflow-y: auto; }
.mail-item {
  padding: 12px 16px;
  border-bottom: 1px solid #f1f3f4;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.mail-item:hover { background: #f8f9fa; }
.mail-item.active { background: var(--blue-soft); }
.mail-item .from { font-size: 13px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mail-item .subject { font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mail-item.unread .from { color: var(--text); font-weight: 700; }
.mail-item.unread .subject { color: var(--text); font-weight: 500; }
.mail-item .meta { font-size: 11px; color: var(--muted); }
.mail-read { flex: 1; min-width: 0; background: var(--surface); overflow-y: auto; padding: 24px 32px; }
.mail-read h2 { font-size: 20px; font-weight: 500; margin: 0 0 12px; }
.mail-meta { color: var(--muted); font-size: 13px; margin-bottom: 24px; }
.mail-body { white-space: pre-wrap; font-size: 14px; line-height: 1.7; }
.mail-read-actions { display: flex; gap: 8px; margin-bottom: 24px; }

/* ---------- dialog ---------- */
dialog {
  border: 0;
  border-radius: var(--radius);
  box-shadow: var(--shadow-2);
  padding: 0;
  width: 640px;
  max-width: calc(100vw - 32px);
  color: var(--text);
}
dialog::backdrop { background: rgba(32, 33, 36, 0.5); }
.dialog-head { padding: 20px 24px 8px; }
.dialog-head h2 { margin: 0; font-size: 20px; font-weight: 500; }
.dialog-body { padding: 8px 24px 8px; }
.dialog-foot { padding: 16px 24px 20px; display: flex; justify-content: flex-end; gap: 8px; }
.dialog-body textarea {
  width: 100%;
  min-height: 200px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px;
  font: inherit;
  font-size: 14px;
  resize: vertical;
}
.dialog-body textarea:focus { outline: none; border-color: var(--blue); }
.dialog-body .field { margin-top: 12px; }

/* ---------- toast ---------- */
.toast {
  position: fixed;
  left: 24px;
  bottom: 24px;
  background: #202124;
  color: #fff;
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-2);
  font-size: 13px;
  opacity: 0;
  transform: translateY(8px);
  transition: all 0.2s ease;
  pointer-events: none;
  z-index: 50;
  max-width: 70vw;
}
.toast.show { opacity: 1; transform: none; }

.muted { color: var(--muted); }
.spin {
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255, 255, 255, 0.4);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 900px) {
  .rail { display: none; }
  .mail-list { width: 100%; }
  .mail-read { display: none; }
  .mail-shell.reading .mail-list { display: none; }
  .mail-shell.reading .mail-read { display: block; }
  .hero { padding: 32px 24px; }
  .hero h1 { font-size: 26px; }
}