:root{
  --ink: #1D2733;
  --ink-soft: #4B5768;
  --slate: #2E3A4C;
  --slate-light: #3C4A60;
  --paper: #FBFAF7;
  --paper-line: #E4E0D6;
  --stamp-red: #B23B2E;
  --stamp-red-dark: #8F2E24;
  --ok-green: #3F6B4E;
  --sidebar-w: 300px;
}

*{ box-sizing: border-box; }

body{
  margin:0;
  min-height:100vh;
  background: var(--slate);
  font-family: 'IBM Plex Sans', sans-serif;
  color: var(--ink);
}

h1,h2{
  font-family: 'Zilla Slab', serif;
  margin:0;
}

.frame{
  display:flex;
  min-height:100vh;
}

.login-page{
  min-height:100vh;
  display:flex;
  align-items:center;
  justify-content:center;
  background: linear-gradient(180deg, #1f2937 0%, #111827 100%);
}

.login-box{
  width: min(420px, calc(100% - 32px));
  background: #FBFAF7;
  border-radius: 16px;
  padding: 32px 28px;
  box-shadow: 0 28px 80px rgba(0, 0, 0, 0.35);
}

.login-brand{
  display:flex;
  align-items:center;
  gap: 14px;
  margin-bottom: 24px;
}

.login-brand h1{
  font-size: 24px;
  margin: 0;
}

.login-brand p{
  margin: 4px 0 0;
  color: #4b5563;
  font-size: 13px;
}

.login-form{
  display:flex;
  flex-direction:column;
  gap: 14px;
}

.login-form label{
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #6b7280;
}

.login-form input{
  border: 1px solid #d6d3d1;
  border-radius: 8px;
  padding: 12px 14px;
  font-size: 15px;
  font-family: 'IBM Plex Sans', sans-serif;
  outline: none;
}

.login-form input:focus{
  border-color: #b23b2e;
}

.login-error{
  background: #fee2e2;
  color: #991b1b;
  padding: 12px 14px;
  border-radius: 8px;
  font-size: 13px;
  margin-bottom: 12px;
}

.login-note{
  margin-top: 18px;
  color: #6b7280;
  font-size: 12px;
  line-height: 1.5;
}

/* ---------- Sidebar / ledger ---------- */

.ledger{
  width: var(--sidebar-w);
  flex-shrink:0;
  background: var(--slate);
  background-image: linear-gradient(180deg, var(--slate) 0%, #26313F 100%);
  color: #E9E7DF;
  padding: 28px 20px;
  display:flex;
  flex-direction:column;
  gap: 20px;
}

.ledger-head{
  display:flex;
  align-items:center;
  gap: 12px;
  padding-bottom: 18px;
  border-bottom: 1px solid rgba(233,231,223,0.15);
}

.mark{
  font-size: 26px;
  color: var(--stamp-red);
  transform: rotate(-8deg);
}

.ledger-head h1{
  font-size: 22px;
  font-weight: 600;
  color: #F5F3EC;
  letter-spacing: 0.02em;
}

.tagline{
  margin: 2px 0 0;
  font-size: 12px;
  color: #9BA7B7;
  font-family: 'IBM Plex Mono', monospace;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.ledger-list{
  display:flex;
  flex-direction:column;
  gap: 8px;
  flex: 1;
  overflow-y: auto;
}

.account-card{
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 6px;
  padding: 12px 14px;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
  position: relative;
}

.account-card:hover{
  background: rgba(255,255,255,0.08);
  border-color: rgba(255,255,255,0.18);
}

.account-card.active{
  background: rgba(178,59,46,0.18);
  border-color: var(--stamp-red);
}

.account-card .acc-name{
  font-weight: 600;
  font-size: 14px;
  color: #F5F3EC;
}

.account-card .acc-email{
  font-family: 'IBM Plex Mono', monospace;
  font-size: 11px;
  color: #9BA7B7;
  margin-top: 3px;
  word-break: break-all;
}

.account-card .acc-edit{
  position:absolute;
  top: 10px;
  right: 10px;
  font-size: 11px;
  color: #9BA7B7;
  background: none;
  border: none;
  cursor: pointer;
  font-family: 'IBM Plex Sans', sans-serif;
  opacity: 0;
  transition: opacity 0.15s ease;
}

.account-card:hover .acc-edit{ opacity: 1; }
.account-card .acc-edit:hover{ color: #F5F3EC; text-decoration: underline; }

.no-accounts{
  color: #8A96A6;
  font-size: 13px;
  padding: 10px 4px;
  line-height: 1.5;
}

.ghost-btn{
  background: none;
  border: 1px dashed rgba(233,231,223,0.35);
  color: #D9D6CB;
  border-radius: 6px;
  padding: 10px 14px;
  font-family: 'IBM Plex Sans', sans-serif;
  font-size: 13px;
  cursor: pointer;
  transition: border-color 0.15s ease, color 0.15s ease;
}

.ghost-btn:hover{
  border-color: var(--stamp-red);
  color: #F5F3EC;
}

/* ---------- Desk / paper ---------- */

.desk{
  flex:1;
  background:
    radial-gradient(circle at 15% 20%, rgba(255,255,255,0.03), transparent 40%),
    var(--slate);
  display:flex;
  align-items:flex-start;
  justify-content:center;
  padding: 48px 32px;
}

.paper{
  position: relative;
  background: var(--paper);
  width: 100%;
  max-width: 680px;
  border-radius: 3px;
  box-shadow: 0 20px 50px rgba(0,0,0,0.35), 0 2px 0 rgba(0,0,0,0.05);
  padding: 40px 44px 32px;
  overflow: hidden;
}

.paper::before{
  content:"";
  position:absolute;
  top:0; left:0; right:0;
  height: 6px;
  background: repeating-linear-gradient(90deg, var(--stamp-red) 0 14px, transparent 14px 24px);
  opacity: 0.55;
}

.paper-corner{
  position: absolute;
  top: 18px;
  right: 24px;
  pointer-events: none;
}

.stamp{
  width: 92px;
  height: 92px;
  border: 3px solid var(--stamp-red);
  border-radius: 50%;
  display:flex;
  flex-direction: column;
  align-items:center;
  justify-content:center;
  color: var(--stamp-red);
  font-family: 'IBM Plex Mono', monospace;
  font-weight: 600;
  letter-spacing: 0.08em;
  transform: rotate(12deg) scale(0.7);
  opacity: 0;
  transition: opacity 0.35s ease, transform 0.35s ease;
}

.stamp.show{
  opacity: 0.9;
  transform: rotate(12deg) scale(1);
}

.stamp #stampText{
  font-size: 13px;
}

.stamp-date{
  font-size: 9px;
  margin-top: 4px;
}

.field-row{
  display:flex;
  align-items:flex-start;
  gap: 16px;
  padding: 12px 0;
  border-bottom: 1px solid var(--paper-line);
}

.field-row label{
  width: 78px;
  flex-shrink: 0;
  padding-top: 8px;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--ink-soft);
  font-weight: 600;
}

.compose-from{
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field-row input[type="text"],
.field-row input[type="password"],
.field-row select,
.field-row textarea{
  flex:1;
  border: none;
  background: transparent;
  font-family: 'IBM Plex Sans', sans-serif;
  font-size: 15px;
  color: var(--ink);
  padding: 8px 0;
  outline: none;
}

.field-row select{
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%234B5768' stroke-width='1.5' fill='none'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 4px center;
  padding-right: 20px;
}

.body-row textarea{
  min-height: 220px;
  resize: vertical;
  line-height: 1.55;
}

.field-row input::placeholder,
.field-row textarea::placeholder{
  color: #B7AF9E;
}

.attach-zone{
  flex:1;
  padding: 4px 0;
}

.attach-zone input[type="file"]{
  font-size: 13px;
  font-family: 'IBM Plex Mono', monospace;
  color: var(--ink-soft);
}

.file-list{
  margin-top: 6px;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 12px;
  color: var(--ink-soft);
  display:flex;
  flex-direction:column;
  gap: 2px;
}

.send-row{
  display:flex;
  align-items:center;
  gap: 16px;
  padding-top: 24px;
}

.send-btn{
  background: var(--stamp-red);
  color: #FBFAF7;
  border: none;
  border-radius: 4px;
  padding: 12px 26px;
  font-family: 'IBM Plex Sans', sans-serif;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.03em;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.1s ease;
}

.send-btn:hover{ background: var(--stamp-red-dark); }
.send-btn:active{ transform: translateY(1px); }
.send-btn:disabled{ opacity: 0.5; cursor: not-allowed; }

.status-line{
  font-size: 13px;
  font-family: 'IBM Plex Mono', monospace;
  color: var(--ink-soft);
}

.history-panel{
  margin-top: 32px;
  border-top: 1px solid var(--paper-line);
  padding-top: 24px;
}

.history-toggle{
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  color: var(--slate);
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  padding: 0;
}

.history-content{
  margin-top: 16px;
  display: none;
  flex-direction: column;
  gap: 14px;
}

.history-entry{
  background: #F6F4EE;
  border: 1px solid #E4E0D6;
  border-radius: 8px;
  padding: 14px 16px;
}

.history-entry .entry-header{
  display: flex;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  font-size: 13px;
  color: var(--ink-soft);
}

.history-entry .entry-summary{
  margin-top: 10px;
  font-size: 13px;
  color: var(--ink);
}

.history-entry .entry-details{
  margin-top: 10px;
  border-top: 1px solid #E4E0D6;
  padding-top: 10px;
  display: none;
  gap: 8px;
  font-size: 13px;
}

.history-entry.open .entry-details{
  display: block;
}

.history-entry .detail-row{
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.history-entry .detail-row span:first-child{
  color: var(--ink-soft);
}

.history-entry .entry-result{
  font-weight: 700;
}

.history-entry .entry-result.ok{ color: var(--ok-green); }
.history-entry .entry-result.bounced{ color: #d16162; }
.history-entry .entry-result.error{ color: var(--stamp-red); }

.status-line.ok{ color: var(--ok-green); }
.status-line.warn{ color: #B97300; }
.status-line.err{ color: var(--stamp-red); }

/* ---------- Modal ---------- */

.modal-backdrop{
  position: fixed;
  inset: 0;
  background: rgba(20,26,34,0.55);
  display:none;
  align-items:center;
  justify-content:center;
  z-index: 50;
}

.modal-backdrop.show{ display:flex; }

.modal{
  background: var(--paper);
  width: 100%;
  max-width: 420px;
  border-radius: 6px;
  padding: 28px 28px 20px;
  box-shadow: 0 24px 60px rgba(0,0,0,0.4);
}

.modal h2{
  font-size: 19px;
  margin-bottom: 16px;
}

.modal-row{
  margin-bottom: 14px;
  display:flex;
  flex-direction:column;
  gap: 5px;
}

.modal-row label{
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink-soft);
  font-weight: 600;
}

.modal-row .hint{
  text-transform: none;
  font-weight: 400;
  letter-spacing: 0;
  color: #A79E8C;
}

.modal-row input,
.modal-row select{
  border: 1px solid var(--paper-line);
  border-radius: 4px;
  padding: 9px 10px;
  font-size: 14px;
  font-family: 'IBM Plex Sans', sans-serif;
  outline: none;
  background: #fff;
}

.modal-row input:focus,
.modal-row select:focus{
  border-color: var(--stamp-red);
}

.modal-split{
  flex-direction: row;
  gap: 12px;
}

.modal-split > div{
  flex:1;
  display:flex;
  flex-direction:column;
  gap: 5px;
}

.modal-actions{
  display:flex;
  align-items:center;
  justify-content:space-between;
  margin-top: 10px;
}

.modal-actions-right{
  display:flex;
  gap: 10px;
}

.text-btn{
  background:none;
  border:none;
  color: var(--stamp-red);
  font-size: 13px;
  cursor:pointer;
  padding: 6px 0;
}

.text-btn:hover{ text-decoration: underline; }

.modal .ghost-btn{
  border-color: var(--paper-line);
  color: var(--ink-soft);
}
.modal .ghost-btn:hover{
  border-color: var(--ink-soft);
  color: var(--ink);
}

.modal-error{
  color: var(--stamp-red);
  font-size: 13px;
  margin-top: 12px;
  min-height: 16px;
}

/* ---------- User Management Table ---------- */
#usersListContainer table {
  width: 100%;
  border-collapse: collapse;
}

#usersListContainer th,
#usersListContainer td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--paper-line);
  font-size: 14px;
}

#usersListContainer th {
  font-weight: 600;
  color: var(--ink-soft);
  text-transform: uppercase;
  font-size: 11px;
  letter-spacing: 0.05em;
}

#usersListBody tr:last-child td {
  border-bottom: none;
}

/* ---------- Responsive ---------- */

@media (max-width: 800px){
  .frame{ flex-direction: column; }
  .ledger{
    width: 100%;
    padding: 20px 16px;
    max-height: 40vh;
  }
  .ledger-list{ max-height: 160px; }
  .desk{ padding: 24px 16px; }
  .paper{ padding: 28px 22px 24px; }
  .field-row{ flex-direction: column; gap: 6px; padding: 14px 0; }
  .field-row label{ width:auto; padding-top:0; }
  .paper-corner{ top: 12px; right: 16px; }
  .stamp{ width: 70px; height: 70px; }
  .stamp #stampText{ font-size: 11px; }
  .send-row{ flex-wrap: wrap; row-gap: 10px; }
}

@media (max-width: 480px){
  .ledger-head h1{ font-size: 19px; }
  .paper{ padding: 24px 16px 20px; max-width: 100%; }
  .paper::before{ height: 4px; }
  .send-btn{ width: 100%; text-align: center; }
  .status-line{ width: 100%; }
  .modal{ max-width: 92vw; padding: 22px 18px 16px; margin: 0 16px; }
  .modal-split{ flex-direction: column; gap: 14px; }
  .modal-actions{ flex-direction: column-reverse; gap: 12px; align-items: stretch; }
  .modal-actions-right{ flex-direction: column-reverse; gap: 8px; }
  .modal-actions-right .send-btn,
  .modal-actions-right .ghost-btn{ width: 100%; }
  .text-btn{ align-self: center; }
  .attach-zone input[type="file"]{ width: 100%; }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce){
  .stamp{ transition: none; }
}
