/* Hesabi Mail — enterprise console, light + dark */

/* Light (default) */
:root,
[data-theme="light"] {
  color-scheme: light;
  --bg: #f6f7f8;
  --surface: #ffffff;
  --surface-raised: #ffffff;
  --border: #d8dce3;
  --border-light: #e8ebef;
  --text: #1c1f26;
  --text-secondary: #5c6573;
  --text-tertiary: #8a939f;
  --accent: #1c1f26;
  --accent-hover: #333842;
  --accent-fg: #ffffff;
  --aside: #1c1f26;
  --aside-muted: #9ca3af;
  --aside-text: #c4c9d0;
  --input-bg: #ffffff;
  --table-head: #fafbfc;
  --table-hover: #fafbfc;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06);
  --toggle-bg: #ffffff;
  --error: #b42318;
  --error-bg: #fef3f2;
  --error-border: #fecdca;
  --success: #027a48;
  --success-bg: #ecfdf3;
  --warn: #b54708;
  --warn-bg: #fffaeb;
  --info: #175cd3;
  --info-bg: #eff8ff;
}

[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0f1114;
  --surface: #181b21;
  --surface-raised: #1e2229;
  --border: #2d333d;
  --border-light: #252a33;
  --text: #eceef1;
  --text-secondary: #a3adb8;
  --text-tertiary: #6b7582;
  --accent: #eceef1;
  --accent-hover: #ffffff;
  --accent-fg: #0f1114;
  --aside: #12151a;
  --aside-muted: #6b7280;
  --aside-text: #9ca3af;
  --input-bg: #12151a;
  --table-head: #1e2229;
  --table-hover: #1e2229;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.35);
  --toggle-bg: #181b21;
  --error: #f97066;
  --error-bg: #2a1513;
  --error-border: #5c2a27;
  --success: #32d583;
  --success-bg: #0f2419;
  --warn: #fdb022;
  --warn-bg: #2a1f0a;
  --info: #53b1fd;
  --info-bg: #0f1f33;
}

:root {
  --font: "Segoe UI", -apple-system, BlinkMacSystemFont, "Helvetica Neue", Arial, sans-serif;
  --mono: "Consolas", "SF Mono", ui-monospace, monospace;
  --radius: 3px;
  --max: 1120px;
  --header-h: 52px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
}

*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  height: 100%;
}

body {
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  min-height: 100%;
  -webkit-font-smoothing: antialiased;
  transition: background 0.2s ease, color 0.2s ease;
}

/* Theme toggle */
.theme-toggle {
  position: fixed;
  top: calc(0.75rem + var(--safe-top));
  right: calc(0.75rem + var(--safe-right));
  z-index: 100;
  display: inline-flex;
  align-items: center;
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  background: var(--toggle-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.4rem 0.65rem;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: border-color 0.15s, color 0.15s, background 0.2s;
}

.theme-toggle:hover {
  color: var(--text);
  border-color: var(--text-tertiary);
}

.theme-toggle-light,
.theme-toggle-dark {
  display: none;
}

[data-theme="light"] .theme-toggle .theme-toggle-dark {
  display: inline;
}

[data-theme="dark"] .theme-toggle .theme-toggle-light {
  display: inline;
}

/* —— Auth —— */

.page-auth {
  background: var(--bg);
}

.auth-layout {
  display: grid;
  grid-template-columns: minmax(280px, 1fr) minmax(320px, 1fr);
  min-height: 100vh;
  min-height: 100dvh;
}

.auth-aside {
  background: var(--aside);
  color: #fff;
  padding: 3rem clamp(1.5rem, 5vw, 3.5rem);
  padding-top: calc(3rem + var(--safe-top));
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.auth-org {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--aside-muted);
  margin-bottom: 2rem;
}

.auth-product {
  font-size: clamp(1.75rem, 4vw, 2.5rem);
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1.1;
  margin-bottom: 0.75rem;
}

.auth-tagline {
  font-size: 15px;
  color: var(--aside-text);
  max-width: 280px;
  margin-bottom: 2.5rem;
}

.auth-mailbox {
  font-family: var(--mono);
  font-size: 13px;
  color: var(--aside-muted);
  word-break: break-all;
}

.auth-main {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: clamp(1.25rem, 4vw, 2rem);
  padding-top: calc(3.5rem + var(--safe-top));
  padding-bottom: calc(1.25rem + var(--safe-bottom));
}

.auth-form-wrap {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  padding: clamp(1.5rem, 4vw, 2.5rem);
  box-shadow: var(--shadow);
  transition: background 0.2s, border-color 0.2s;
}

.auth-form-wrap h2 {
  font-size: 1.25rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  margin-bottom: 0.35rem;
}

.auth-sub {
  color: var(--text-secondary);
  font-size: 13px;
  margin-bottom: 1.75rem;
}

.auth-foot {
  margin-top: 2rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border-light);
  font-size: 12px;
  color: var(--text-tertiary);
  word-break: break-word;
}

/* —— Forms —— */

.form-stack {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.form-wide {
  max-width: 720px;
  width: 100%;
}

.field {
  display: block;
}

.field-label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 0.4rem;
}

input,
textarea {
  width: 100%;
  font: inherit;
  font-size: 16px;
  color: var(--text);
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.6rem 0.65rem;
  transition: border-color 0.15s, background 0.2s;
}

@media (min-width: 769px) {
  input,
  textarea {
    font-size: 14px;
  }
}

input::placeholder {
  color: var(--text-tertiary);
}

input:hover,
textarea:hover {
  border-color: var(--text-tertiary);
}

input:focus,
textarea:focus {
  outline: 2px solid var(--text);
  outline-offset: 0;
  border-color: var(--text);
}

textarea {
  resize: vertical;
  min-height: 160px;
  line-height: 1.55;
}

@media (min-width: 769px) {
  textarea {
    min-height: 200px;
  }
}

.btn {
  display: inline-block;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  color: var(--accent-fg);
  background: var(--accent);
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  padding: 0.6rem 1.25rem;
  min-height: 44px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.2s;
}

@media (min-width: 769px) {
  .btn {
    min-height: auto;
    padding: 0.55rem 1.25rem;
  }
}

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

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.form-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 1rem;
  padding-top: 0.25rem;
}

.form-feedback {
  font-size: 13px;
  color: var(--text-secondary);
  flex: 1;
  min-width: 120px;
}

.form-feedback.ok {
  color: var(--success);
}

.form-feedback.err {
  color: var(--error);
}

.notice {
  font-size: 13px;
  padding: 0.65rem 0.75rem;
  margin-bottom: 1.25rem;
  border-radius: var(--radius);
}

.notice-error {
  color: var(--error);
  background: var(--error-bg);
  border: 1px solid var(--error-border);
}

/* —— App shell —— */

.page-app {
  background: var(--bg);
  padding-bottom: var(--safe-bottom);
}

.shell {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.shell-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.5rem 1rem;
  min-height: var(--header-h);
  padding: 0.5rem clamp(1rem, 3vw, 1.5rem);
  padding-top: calc(0.5rem + var(--safe-top));
  padding-right: calc(clamp(1rem, 3vw, 1.5rem) + 4.5rem);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  transition: background 0.2s, border-color 0.2s;
}

.shell-brand {
  display: flex;
  align-items: baseline;
  gap: 0.35rem;
  font-size: 15px;
  min-width: 0;
}

.shell-logo {
  font-weight: 600;
  letter-spacing: -0.02em;
}

.shell-divider,
.shell-module {
  color: var(--text-tertiary);
  font-weight: 400;
}

.shell-meta {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem 1rem;
  font-size: 13px;
}

.shell-stats {
  color: var(--text-secondary);
}

.shell-stats strong {
  font-weight: 600;
  color: var(--text);
}

.shell-stat-sep {
  margin: 0 0.35rem;
  color: var(--border);
}

.shell-user {
  color: var(--text-secondary);
}

.shell-logout {
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 13px;
  padding: 0.35rem 0;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
}

.shell-logout:hover {
  color: var(--text);
  text-decoration: underline;
}

.shell-stats-mobile {
  display: none;
  width: 100%;
  padding: 0.65rem clamp(1rem, 3vw, 1.5rem);
  background: var(--surface-raised);
  border-bottom: 1px solid var(--border-light);
  font-size: 12px;
  color: var(--text-secondary);
  gap: 1rem;
}

.shell-stats-mobile strong {
  color: var(--text);
  font-weight: 600;
}

.shell-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: var(--max);
  margin: 0 auto;
  padding: 0 clamp(1rem, 3vw, 1.5rem) 2rem;
}

.tabs {
  display: flex;
  gap: 0;
  margin-top: 1rem;
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

.tabs::-webkit-scrollbar {
  display: none;
}

.tab {
  font: inherit;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  padding: 0.75rem 1rem;
  min-height: 44px;
  white-space: nowrap;
  cursor: pointer;
  flex-shrink: 0;
  transition: color 0.15s;
}

.tab:hover {
  color: var(--text);
}

.tab.active {
  color: var(--text);
  font-weight: 600;
  border-bottom-color: var(--text);
}

.content {
  padding-top: 1.5rem;
  width: 100%;
  min-width: 0;
}

.content-head {
  margin-bottom: 1.25rem;
}

.content-head h1 {
  font-size: 1.125rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  margin-bottom: 0.2rem;
}

.content-desc {
  font-size: 13px;
  color: var(--text-secondary);
  word-break: break-word;
}

.panel {
  display: none;
}

.panel.active {
  display: block;
}

.shell-footer {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 1rem clamp(1rem, 3vw, 1.5rem);
  padding-bottom: calc(1rem + var(--safe-bottom));
  font-size: 12px;
  color: var(--text-tertiary);
  border-top: 1px solid var(--border-light);
  background: var(--surface);
  transition: background 0.2s;
}

/* —— Tables —— */

.table-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  transition: background 0.2s, border-color 0.2s;
}

.table {
  width: 100%;
  min-width: 560px;
  border-collapse: collapse;
  font-size: 13px;
}

.table th,
.table td {
  text-align: left;
  padding: 0.7rem 1rem;
  border-bottom: 1px solid var(--border-light);
  vertical-align: top;
}

.table th {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-tertiary);
  background: var(--table-head);
  white-space: nowrap;
  position: sticky;
  top: 0;
  z-index: 1;
}

.table tbody tr:hover td {
  background: var(--table-hover);
}

.table tbody tr:last-child td {
  border-bottom: none;
}

.table .cell-muted {
  color: var(--text-secondary);
}

.status {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  padding: 0.15rem 0.45rem;
  border-radius: 2px;
}

.status-sent {
  color: var(--success);
  background: var(--success-bg);
}

.status-failed {
  color: var(--error);
  background: var(--error-bg);
}

.status-info {
  color: var(--info);
  background: var(--info-bg);
}

.status-error {
  color: var(--error);
  background: var(--error-bg);
}

.status-warn {
  color: var(--warn);
  background: var(--warn-bg);
}

.empty-row td {
  text-align: center;
  color: var(--text-tertiary);
  padding: 2.5rem 1rem;
}

/* —— Responsive —— */

@media (max-width: 900px) {
  .auth-layout {
    grid-template-columns: 1fr;
  }

  .auth-aside {
    padding: 2rem 1.5rem 1.5rem;
    padding-top: calc(3.25rem + var(--safe-top));
  }

  .auth-tagline {
    margin-bottom: 1rem;
  }

  .auth-main {
    padding-top: 1.25rem;
  }
}

@media (max-width: 640px) {
  .shell-header .shell-stats {
    display: none;
  }

  .shell-stats-mobile {
    display: flex;
    flex-wrap: wrap;
  }

  .shell-user {
    max-width: 120px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .shell-meta {
    width: 100%;
    justify-content: space-between;
  }

  .shell-brand {
    flex: 1;
  }

  .table {
    min-width: 480px;
    font-size: 12px;
  }

  .table th,
  .table td {
    padding: 0.6rem 0.75rem;
  }

  .auth-form-wrap {
    border-left: none;
    border-right: none;
    box-shadow: none;
  }

  .page-auth .theme-toggle {
    top: calc(0.5rem + var(--safe-top));
  }
}

@media (min-width: 641px) {
  .shell-user {
    padding-left: 1rem;
    border-left: 1px solid var(--border-light);
  }
}

@media (min-width: 769px) {
  .shell-header {
    flex-wrap: nowrap;
    padding-right: calc(clamp(1rem, 3vw, 1.5rem) + 4.5rem);
  }
}

@media (prefers-reduced-motion: reduce) {
  body,
  .theme-toggle,
  .auth-form-wrap,
  .shell-header,
  .table-panel,
  input,
  textarea {
    transition: none;
  }
}
