:root {
  --primary-green: #769E5C;
  --accent-green:  #597745;
  --light-green:   #8DB470;
  --neon-green:    #9FE870;
  --dark-bg:       #0F1419;
  --dark-surface:  #1A1F26;
  --dark-elevated: #242B33;
  --text-primary:  #FFFFFF;
  --text-secondary:#A0A9B8;
  --border-dark:   rgba(159,232,112,0.2);
  --ui-panel:      #111418;
  --ui-border:     #1e242c;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }

body {
  font-family: 'Montserrat', sans-serif;
  background: var(--dark-bg);
  color: var(--text-primary);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

header {
  background: var(--dark-surface);
  border-bottom: 1px solid var(--border-dark);
  padding: .85rem 1.75rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
  box-shadow: 0 4px 24px rgba(0,0,0,.4);
}

.logo { display: flex; align-items: center; gap: .55rem; text-decoration: none; color: inherit; }
.logo-icon {
  width: 32px; height: 32px;
  background: linear-gradient(135deg, var(--primary-green), var(--neon-green));
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 4px 16px rgba(159,232,112,.3);
}
.logo-icon svg { width: 17px; height: 17px; stroke: #0F1419; fill: none; stroke-width: 2.5; stroke-linecap: round; }
.logo-name { font-size: 1.15rem; font-weight: 800; letter-spacing: -.3px; }
.logo-badge {
  font-size: .6rem; font-weight: 700; letter-spacing: .12em; text-transform: uppercase;
  padding: 2px 8px; border-radius: 20px;
  background: rgba(159,232,112,.1); color: var(--neon-green);
  border: 1px solid rgba(159,232,112,.2);
}

.header-right {
  font-size: .62rem;
  font-weight: 700;
  color: #3b4550;
  text-transform: uppercase;
  letter-spacing: .1em;
  display: flex;
  align-items: center;
  gap: 12px;
}

.header-right span:first-child {
  color: var(--neon-green);
  background: rgba(159,232,112,.08);
  padding: 2px 8px;
  border-radius: 4px;
}

.main { display: flex; flex: 1; overflow: hidden; }

.sidebar {
  width: 280px; min-width: 280px;
  background: var(--ui-panel);
  border-right: 1px solid var(--ui-border);
  display: flex; flex-direction: column;
  overflow-y: auto;
}
.sidebar::-webkit-scrollbar { width: 4px; }
.sidebar::-webkit-scrollbar-thumb { background: var(--ui-border); border-radius: 2px; }

.sb-section { padding: .9rem 1rem; border-bottom: 1px solid var(--ui-border); }
.sb-label {
  font-size: .6rem; font-weight: 700; letter-spacing: .14em;
  color: #2e3a44; text-transform: uppercase;
  margin-bottom: .55rem; padding-left: 4px;
}

.tpl-btn {
  width: 100%; display: flex; align-items: center; gap: .65rem;
  padding: .52rem .6rem; border-radius: 8px; border: 1px solid transparent;
  background: none; color: var(--text-secondary);
  font-family: 'Montserrat', sans-serif; font-size: .77rem; font-weight: 600;
  cursor: pointer; text-align: left; transition: all .15s; margin-bottom: 2px;
  text-decoration: none;
}
.tpl-btn:hover { background: rgba(255,255,255,.04); color: var(--text-primary); }
.tpl-btn.active {
  background: rgba(159,232,112,.07); border-color: rgba(159,232,112,.25); color: var(--neon-green);
}
.tpl-icon {
  width: 29px; height: 29px; border-radius: 7px;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; flex-shrink: 0; background: rgba(255,255,255,.05);
}
.tpl-btn.active .tpl-icon { background: rgba(159,232,112,.1); }
.tpl-name { font-size: .77rem; font-weight: 700; }
.tpl-desc { font-size: .61rem; color: #2e3a44; font-weight: 500; margin-top: 1px; }

.field { margin-bottom: .6rem; }
.f-label {
  font-size: .6rem; font-weight: 700; color: #3a4a5a;
  text-transform: uppercase; letter-spacing: .08em;
  display: block; margin-bottom: .28rem;
}
.f-input {
  width: 100%; background: rgba(255,255,255,.04); border: 1px solid var(--ui-border);
  border-radius: 6px; color: var(--text-primary);
  font-family: 'Montserrat', sans-serif; font-size: .75rem; font-weight: 500;
  padding: .4rem .6rem; outline: none; transition: border-color .15s;
}
.f-input:focus { border-color: rgba(159,232,112,0.35); }

.preview-panel { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
.toolbar {
  background: var(--dark-surface); border-bottom: 1px solid var(--ui-border);
  padding: .52rem 1.2rem; display: flex; align-items: center;
  justify-content: space-between; flex-shrink: 0;
}

.view-tabs { display: flex; gap: 3px; background: rgba(0,0,0,.3); border-radius: 8px; padding: 3px; }
.vtab {
  padding: .26rem .85rem; border-radius: 6px; border: none; background: none;
  color: var(--text-secondary); font-family: 'Montserrat', sans-serif;
  font-size: .71rem; font-weight: 700; cursor: pointer; transition: all .15s;
}
.vtab.active { background: var(--dark-elevated); color: var(--text-primary); }

.subject-pill {
  font-size: .67rem; color: #3a4a5a; font-weight: 500;
  padding: .22rem .65rem; background: rgba(255,255,255,.02);
  border: 1px solid var(--ui-border); border-radius: 20px;
  max-width: 340px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.action-btn:hover { box-shadow: 0 6px 22px rgba(159,232,112,.38); transform: translateY(-1px); }

.copy-btn {
  display: flex; align-items: center; gap: 6px;
  padding: .4rem 1rem; background: linear-gradient(135deg, var(--primary-green), var(--neon-green));
  color: #0F1419; border: none; border-radius: 6px;
  font-family: 'Montserrat', sans-serif; font-size: .71rem; font-weight: 800;
  cursor: pointer; transition: all .18s; letter-spacing: .02em;
  box-shadow: 0 4px 14px rgba(159,232,112,.22);
}
.copy-btn:hover { box-shadow: 0 6px 22px rgba(159,232,112,.38); transform: translateY(-1px); }
.copy-btn.ok { background: linear-gradient(135deg, #597745, #8DB470); }

.preview-wrap {
  flex: 1; overflow: auto; padding: 2rem;
  background: radial-gradient(ellipse at 50% 0%, rgba(159,232,112,.04) 0%, transparent 60%), #0a0d10;
}
.preview-wrap::-webkit-scrollbar { width: 6px; }
.preview-wrap::-webkit-scrollbar-thumb { background: #1e242c; border-radius: 3px; }

.email-shell {
  max-width: 640px; margin: 0 auto; border-radius: 14px;
  overflow: hidden; box-shadow: 0 30px 80px rgba(0,0,0,.7), 0 0 0 1px rgba(159,232,112,.07);
}

.code-wrap { flex: 1; overflow: auto; display: none; background: #080b0e; }
.code-wrap pre {
  font-family: 'DM Mono', monospace; font-size: .67rem; color: #7ab868;
  line-height: 1.75; padding: 1.5rem; white-space: pre-wrap; word-break: break-all;
}

/* Auth Page */
.auth-wrap {
  display: flex; align-items: center; justify-content: center; height: 100vh;
  background: radial-gradient(circle at center, rgba(159,232,112,.05) 0%, transparent 70%), var(--dark-bg);
}
.auth-card {
  width: 100%; max-width: 380px; padding: 2.5rem;
  background: var(--dark-surface); border: 1px solid var(--border-dark);
  border-radius: 20px; box-shadow: 0 20px 50px rgba(0,0,0,.5);
}
.auth-title { font-size: 1.5rem; font-weight: 900; letter-spacing: -.5px; margin-bottom: .5rem; text-align: center; }
.auth-subtitle { font-size: .8rem; color: var(--text-secondary); text-align: center; margin-bottom: 2rem; }

/* Dashboard Cards (for index) */
.tpl-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 1rem; padding: 1.5rem; }
.card { background: var(--dark-surface); border: 1px solid var(--ui-border); border-radius: 12px; padding: 1.2rem; transition: all .2s; cursor: pointer; }
.card:hover { border-color: var(--border-dark); background: var(--dark-elevated); transform: translateY(-4px); }
.card-header { display: flex; align-items: center; gap: .7rem; margin-bottom: .8rem; }
.card-icon { width: 32px; height: 32px; background: rgba(159,232,112,.1); border-radius: 8px; display: flex; align-items: center; justify-content: center; font-size: 14px; }
.card-name { font-size: .9rem; font-weight: 700; }
.card-subject { font-size: .7rem; color: var(--text-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Editor Specifics */
.editor-main { flex: 1; display: flex; overflow: hidden; }
.editor-area { flex: 1; display: flex; flex-direction: column; background: #080b0e; }
.editor-textarea {
  flex: 1; background: transparent; border: none; color: #7ab868;
  font-family: 'DM Mono', monospace; font-size: .75rem; line-height: 1.7;
  padding: 1.5rem; outline: none; resize: none; width: 100%;
}
.preview-area { flex: 1; overflow: auto; background: #0a0d10; padding: 2rem; }

.dl-btn {
  width: 100%; display: flex; align-items: center; gap: .6rem; padding: .52rem .6rem;
  border-radius: 8px; background: rgba(118,158,92,.08); border: 1px solid rgba(118,158,92,.2);
  color: var(--primary-green); font-family: 'Montserrat', sans-serif; font-size: .74rem; font-weight: 700;
  cursor: pointer; transition: all .15s; text-decoration: none;
}
.dl-btn:hover { background: rgba(118,158,92,16); color: var(--neon-green); }

/* --- Responsiveness & Mobile Menu --- */
.mobile-toggle { display: none; background: none; border: none; color: var(--text-primary); cursor: pointer; padding: 5px; }
.mobile-toggle svg { width: 24px; height: 24px; }

@media (max-width: 900px) {
  .hide-mobile { display: none !important; }
  header { padding: .85rem 1rem; }
  .logo-name { font-size: 1rem; }
  .logo-badge { display: none; }
  .header-right { display: none !important; }
  
  .mobile-toggle { display: block; }
  
  .main { position: relative; }
  
  .sidebar { 
    position: absolute; 
    top: 0; 
    left: -281px; 
    bottom: 0; 
    z-index: 1000; 
    transition: left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 20px 0 50px rgba(0,0,0,0.5);
    background: var(--dark-surface);
  }
  
  .main.sb-open .sidebar { left: 0; }
  
  .sidebar-overlay {
    display: none;
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.6);
    backdrop-filter: blur(4px);
    z-index: 999;
  }
  .main.sb-open .sidebar-overlay { display: block; }
  
  .preview-panel { width: 100%; }
  .toolbar { padding: .52rem .8rem; }
  .subject-pill { font-size: .6rem; max-width: 180px; }
  .copy-btn { padding: .4rem .6rem; span { display: none; } }
  .copy-btn svg { margin: 0; }
  
  .preview-wrap { padding: 1rem; }
  .email-shell { width: 100% !important; border-radius: 8px; }
  
  /* Settings/Grid */
  .grid { grid-template-columns: 1fr; }
  .field { margin-bottom: 1.2rem; }
}

@media (max-width: 480px) {
  .vtab { padding: .26rem .5rem; font-size: .65rem; }
  .btn-save { width: 100%; }
  .sender-item { flex-direction: column; align-items: stretch; gap: 5px; background: rgba(255,255,255,0.02); padding: 10px; border-radius: 10px; margin-bottom: 15px; }
  .sender-item .btn-remove { width: 100%; height: 32px; }
}
