:root{
  --brand:#8b5cf6;
  --brand-2:#ec4899;
  --brand-3:#06b6d4;
  --bg:#0b1020;
  --surface:rgba(255,255,255,.78);
  --surface-strong:rgba(255,255,255,.92);
  --text:#111827;
  --muted:#6b7280;
  --line:rgba(148,163,184,.28);
  --sidebar:#080b16;
  --shadow:0 24px 80px rgba(15,23,42,.18);
  --radius:24px;
}

*{box-sizing:border-box}

html{
  min-height:100%;
  background:
    radial-gradient(circle at top left, rgba(139,92,246,.34), transparent 32rem),
    radial-gradient(circle at top right, rgba(236,72,153,.22), transparent 28rem),
    linear-gradient(135deg,#eef2ff 0%,#fdf2f8 48%,#ecfeff 100%);
}

body{
  margin:0;
  min-height:100vh;
  font-family:Inter,ui-sans-serif,system-ui,-apple-system,BlinkMacSystemFont,"Segoe UI",Arial,sans-serif;
  color:var(--text);
  background:
    radial-gradient(circle at 85% 10%, rgba(6,182,212,.18), transparent 22rem),
    radial-gradient(circle at 20% 90%, rgba(139,92,246,.18), transparent 24rem);
}

body:before{
  content:"";
  position:fixed;
  inset:0;
  pointer-events:none;
  background-image:linear-gradient(rgba(255,255,255,.18) 1px,transparent 1px),linear-gradient(90deg,rgba(255,255,255,.18) 1px,transparent 1px);
  background-size:48px 48px;
  mask-image:linear-gradient(to bottom,rgba(0,0,0,.22),transparent 70%);
}

aside{
  position:fixed;
  inset:16px auto 16px 16px;
  width:260px;
  padding:22px;
  color:#fff;
  background:
    linear-gradient(180deg,rgba(15,23,42,.96),rgba(8,11,22,.92)),
    radial-gradient(circle at top left,rgba(139,92,246,.42),transparent 18rem);
  border:1px solid rgba(255,255,255,.12);
  border-radius:28px;
  box-shadow:0 28px 90px rgba(15,23,42,.36);
  backdrop-filter:blur(24px);
}

aside h2{
  margin:0 0 22px;
  font-size:19px;
  letter-spacing:-.04em;
  line-height:1.15;
}

aside h2:before{
  content:"✦";
  display:inline-grid;
  place-items:center;
  width:34px;
  height:34px;
  margin-right:10px;
  border-radius:12px;
  background:linear-gradient(135deg,var(--brand),var(--brand-2));
  box-shadow:0 12px 30px rgba(139,92,246,.45);
}

aside a{
  display:flex;
  align-items:center;
  gap:10px;
  color:rgba(255,255,255,.82);
  text-decoration:none;
  padding:12px 13px;
  margin:4px 0;
  border:1px solid transparent;
  border-radius:16px;
  transition:.18s ease;
}

aside a:hover{
  color:#fff;
  background:rgba(255,255,255,.1);
  border-color:rgba(255,255,255,.12);
  transform:translateX(2px);
}

main{
  position:relative;
  z-index:1;
  margin-left:292px;
  padding:34px;
  max-width:1440px;
}

h1{
  margin:0 0 18px;
  font-size:clamp(30px,4vw,48px);
  line-height:1.02;
  letter-spacing:-.06em;
  color:#0f172a;
}

h2,h3{
  letter-spacing:-.035em;
  color:#111827;
}

a{
  color:#6d28d9;
  font-weight:650;
}

.card{
  position:relative;
  background:var(--surface);
  border:1px solid rgba(255,255,255,.62);
  border-radius:var(--radius);
  padding:22px;
  margin:18px 0;
  box-shadow:var(--shadow);
  backdrop-filter:blur(22px);
}

.card:before{
  content:"";
  position:absolute;
  inset:0;
  border-radius:inherit;
  pointer-events:none;
  background:linear-gradient(135deg,rgba(255,255,255,.55),transparent 42%);
}

.grid{
  display:grid;
  grid-template-columns:repeat(auto-fit,minmax(180px,1fr));
  gap:18px;
}

.grid .card{
  overflow:hidden;
}

.grid .card strong{
  display:block;
  font-size:42px;
  line-height:1;
  letter-spacing:-.08em;
  background:linear-gradient(135deg,var(--brand),var(--brand-2),var(--brand-3));
  -webkit-background-clip:text;
  background-clip:text;
  color:transparent;
}

.grid .card span{
  display:block;
  margin-top:10px;
  text-transform:capitalize;
  color:var(--muted);
  font-weight:650;
}

label{
  display:block;
  margin:8px 0 6px;
  color:#374151;
  font-size:13px;
  font-weight:750;
}

input,select,textarea{
  width:100%;
  padding:13px 14px;
  border:1px solid rgba(148,163,184,.42);
  border-radius:16px;
  margin:6px 0 15px;
  color:#111827;
  background:rgba(255,255,255,.72);
  outline:none;
  box-shadow:inset 0 1px 0 rgba(255,255,255,.7);
  transition:border-color .16s ease, box-shadow .16s ease, background .16s ease;
}

input:focus,select:focus,textarea:focus{
  border-color:rgba(139,92,246,.72);
  background:#fff;
  box-shadow:0 0 0 5px rgba(139,92,246,.13);
}

textarea{
  min-height:180px;
  resize:vertical;
  font-family:ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;
}

button{
  appearance:none;
  border:0;
  padding:12px 18px;
  border-radius:16px;
  cursor:pointer;
  color:#fff;
  font-weight:800;
  letter-spacing:-.02em;
  background:linear-gradient(135deg,var(--brand),var(--brand-2));
  box-shadow:0 14px 34px rgba(139,92,246,.32);
  transition:transform .16s ease, box-shadow .16s ease, filter .16s ease;
}

button:hover{
  transform:translateY(-1px);
  filter:saturate(1.08);
  box-shadow:0 18px 44px rgba(139,92,246,.38);
}

button:active{
  transform:translateY(0);
}

.form-row{
  display:grid;
  grid-template-columns:repeat(auto-fit,minmax(200px,1fr));
  gap:14px;
  align-items:end;
}

table{
  width:100%;
  border-collapse:separate;
  border-spacing:0;
  overflow:hidden;
  background:var(--surface-strong);
  border:1px solid rgba(255,255,255,.62);
  border-radius:22px;
  box-shadow:var(--shadow);
  backdrop-filter:blur(22px);
}

th,td{
  text-align:left;
  padding:15px 16px;
  border-bottom:1px solid var(--line);
  vertical-align:top;
}

th{
  color:#475569;
  font-size:12px;
  text-transform:uppercase;
  letter-spacing:.08em;
  background:rgba(248,250,252,.72);
}

tr:last-child td{
  border-bottom:0;
}

pre{
  white-space:pre-wrap;
  max-width:760px;
  background:rgba(15,23,42,.92);
  color:#e5e7eb;
  border-radius:18px;
  padding:16px;
  overflow:auto;
}

.login{
  display:grid;
  place-items:center;
  min-height:100vh;
  padding:24px;
}

.login-card{
  width:min(440px,92vw);
  padding:30px;
  background:rgba(255,255,255,.78);
}

.login-card h1{
  font-size:32px;
  margin-bottom:24px;
  text-align:center;
}

.error{
  display:block;
  color:#be123c;
  background:#fff1f2;
  border:1px solid #fecdd3;
  padding:10px 12px;
  border-radius:14px;
}

.preview{
  width:100%;
  min-height:680px;
  background:#fff;
  border:1px solid rgba(148,163,184,.34);
  border-radius:22px;
  box-shadow:var(--shadow);
}

@media (max-width:860px){
  aside{
    position:static;
    width:auto;
    margin:14px;
  }
  main{
    margin-left:0;
    padding:16px;
  }
}

/* Theme and language controls */
.sidebar-tools{
  position:absolute;
  left:22px;
  right:22px;
  bottom:22px;
  display:grid;
  gap:12px;
}

.theme-toggle{
  width:100%;
  background:rgba(255,255,255,.1);
  border:1px solid rgba(255,255,255,.14);
  box-shadow:none;
}

.language-switcher{
  display:grid;
  grid-template-columns:repeat(3,1fr);
  gap:6px;
  padding:6px;
  border-radius:18px;
  background:rgba(255,255,255,.08);
  border:1px solid rgba(255,255,255,.1);
}

.language-switcher button{
  padding:9px 6px;
  border-radius:13px;
  font-size:12px;
  background:transparent;
  color:rgba(255,255,255,.7);
  box-shadow:none;
}

.language-switcher button.active{
  color:#fff;
  background:linear-gradient(135deg,var(--brand),var(--brand-2));
}

/* Light mode */
html[data-theme="light"]{
  background:
    radial-gradient(circle at top left, rgba(139,92,246,.24), transparent 32rem),
    radial-gradient(circle at top right, rgba(236,72,153,.16), transparent 28rem),
    linear-gradient(135deg,#f8fafc 0%,#fdf2f8 48%,#ecfeff 100%);
}

html[data-theme="light"] body{
  background:
    radial-gradient(circle at 85% 10%, rgba(6,182,212,.12), transparent 22rem),
    radial-gradient(circle at 20% 90%, rgba(139,92,246,.12), transparent 24rem);
}

html[data-theme="light"] aside{
  background:
    linear-gradient(180deg,rgba(255,255,255,.86),rgba(248,250,252,.82)),
    radial-gradient(circle at top left,rgba(139,92,246,.22),transparent 18rem);
  color:#111827;
  border-color:rgba(148,163,184,.34);
}

html[data-theme="light"] aside a{
  color:#334155;
}

html[data-theme="light"] aside a:hover{
  color:#111827;
  background:rgba(15,23,42,.06);
  border-color:rgba(15,23,42,.08);
}

html[data-theme="light"] .theme-toggle{
  background:rgba(15,23,42,.06);
  border-color:rgba(15,23,42,.08);
  color:#111827;
}

html[data-theme="light"] .language-switcher{
  background:rgba(15,23,42,.05);
  border-color:rgba(15,23,42,.08);
}

html[data-theme="light"] .language-switcher button{
  color:#475569;
}

html[data-theme="light"] .language-switcher button.active{
  color:#fff;
}

@media (max-width:860px){
  .sidebar-tools{
    position:static;
    margin-top:18px;
  }
}

/* Fix StartDM logo sizing */
aside .brand-block{
  display:grid;
  grid-template-columns:1fr;
  justify-items:start;
  gap:10px;
  overflow:hidden;
}

aside .brand-logo{
  display:block;
  width:160px !important;
  max-width:100% !important;
  height:auto !important;
  max-height:70px !important;
  object-fit:contain !important;
  border-radius:0 !important;
  background:transparent !important;
  padding:0 !important;
}

aside .brand-text{
  display:none;
}

@media (max-width:860px){
  aside .brand-logo{
    width:132px !important;
    max-height:56px !important;
  }
}

/* RTL language layout fixes */
html[dir="rtl"] body{
  direction:rtl;
  text-align:right;
}

html[dir="rtl"] aside{
  left:auto;
  right:16px;
}

html[dir="rtl"] main{
  margin-left:0;
  margin-right:292px;
  direction:rtl;
  text-align:right;
}

html[dir="rtl"] aside a{
  justify-content:flex-start;
  text-align:right;
}

html[dir="rtl"] .grid .card,
html[dir="rtl"] .card,
html[dir="rtl"] table,
html[dir="rtl"] th,
html[dir="rtl"] td{
  text-align:right;
}

html[dir="rtl"] input,
html[dir="rtl"] select,
html[dir="rtl"] textarea{
  direction:rtl;
  text-align:right;
}

html[dir="rtl"] .brand-block{
  justify-items:end;
}

html[dir="rtl"] .sidebar-tools{
  left:22px;
  right:22px;
}

@media (max-width:860px){
  html[dir="rtl"] aside{
    right:auto;
  }

  html[dir="rtl"] main{
    margin-right:0;
    margin-left:0;
  }
}

/* RTL logo and sidebar polish */
html[dir="rtl"] aside .brand-block{
  justify-items:start !important;
  text-align:right;
}

html[dir="rtl"] aside .brand-logo{
  margin-left:auto;
  margin-right:0;
}

html[dir="rtl"] aside{
  text-align:right;
}

html[dir="rtl"] .language-switcher{
  direction:ltr;
}

/* Protected Yekan Bakh font loading */
@font-face{
  font-family:"Yekan Bakh";
  src:url("/fonts/yekan-bakh-en-04-regular.ttf") format("truetype");
  font-weight:400;
  font-style:normal;
  font-display:swap;
}

@font-face{
  font-family:"Yekan Bakh";
  src:url("/fonts/yekan-bakh-en-05-medium.ttf") format("truetype");
  font-weight:500;
  font-style:normal;
  font-display:swap;
}

@font-face{
  font-family:"Yekan Bakh";
  src:url("/fonts/yekan-bakh-en-06-bold.ttf") format("truetype");
  font-weight:700;
  font-style:normal;
  font-display:swap;
}

@font-face{
  font-family:"Yekan Bakh";
  src:url("/fonts/yekan-bakh-en-07-heavy.ttf") format("truetype");
  font-weight:800;
  font-style:normal;
  font-display:swap;
}

body,
input,
select,
textarea,
button{
  font-family:"Yekan Bakh", Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif !important;
}

/* Protected Yekan Bakh font loading */
@font-face{
  font-family:"Yekan Bakh";
  src:url("/fonts/yekan-bakh-en-04-regular.ttf") format("truetype");
  font-weight:400;
  font-style:normal;
  font-display:swap;
}

@font-face{
  font-family:"Yekan Bakh";
  src:url("/fonts/yekan-bakh-en-05-medium.ttf") format("truetype");
  font-weight:500;
  font-style:normal;
  font-display:swap;
}

@font-face{
  font-family:"Yekan Bakh";
  src:url("/fonts/yekan-bakh-en-06-bold.ttf") format("truetype");
  font-weight:700;
  font-style:normal;
  font-display:swap;
}

@font-face{
  font-family:"Yekan Bakh";
  src:url("/fonts/yekan-bakh-en-07-heavy.ttf") format("truetype");
  font-weight:800;
  font-style:normal;
  font-display:swap;
}

body,
input,
select,
textarea,
button{
  font-family:"Yekan Bakh", Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif !important;
}

/* Gallery */
.gallery-grid{
  display:grid;
  grid-template-columns:repeat(auto-fill,minmax(280px,1fr));
  gap:22px;
  margin-top:22px;
}

.gallery-card{
  overflow:hidden;
  border-radius:24px;
  background:rgba(255,255,255,.78);
  border:1px solid rgba(255,255,255,.62);
  box-shadow:0 24px 80px rgba(15,23,42,.16);
  backdrop-filter:blur(22px);
}

.gallery-card img{
  display:block;
  width:100%;
  height:210px;
  object-fit:cover;
  background:#f1f5f9;
}

.gallery-body{
  padding:18px;
}

.gallery-body strong{
  display:block;
  font-size:14px;
  line-height:1.35;
  word-break:break-word;
}

.gallery-body small{
  display:block;
  margin:6px 0 14px;
  color:var(--muted);
  word-break:break-word;
}

.gallery-actions{
  display:grid;
  grid-template-columns:1fr 1fr 1fr;
  gap:8px;
  margin-top:8px;
}

.gallery-actions button{
  padding:10px 8px;
  font-size:12px;
  border-radius:13px;
}

.gallery-actions .danger{
  background:linear-gradient(135deg,#ef4444,#be123c);
  box-shadow:0 14px 34px rgba(239,68,68,.26);
}

html[data-theme="light"] .gallery-card{
  background:rgba(255,255,255,.88);
  border-color:rgba(148,163,184,.28);
}

@media (max-width:860px){
  .gallery-grid{
    grid-template-columns:1fr;
  }

  .gallery-actions{
    grid-template-columns:1fr;
  }
}

/* Gallery edit mode toggle */
.gallery-header{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:18px;
  margin-bottom:18px;
}

.gallery-subtitle{
  margin-top:-8px;
  color:var(--muted);
}

.edit-toggle{
  display:flex;
  align-items:center;
  gap:10px;
  width:auto;
  padding:12px 16px;
  border-radius:18px;
  background:rgba(255,255,255,.72);
  border:1px solid rgba(148,163,184,.28);
  box-shadow:0 12px 34px rgba(15,23,42,.08);
  cursor:pointer;
}

.edit-toggle input{
  width:auto;
  margin:0;
}

.gallery-edit-panel{
  display:none;
  margin-top:14px;
}

body.gallery-edit-mode .gallery-edit-panel{
  display:block;
}

body.gallery-edit-mode .simple-actions{
  display:none;
}

.simple-actions{
  grid-template-columns:1fr;
}

.gallery-info{
  font-size:14px;
  color:#334155;
}

@media (max-width:860px){
  .gallery-header{
    display:grid;
  }

  .edit-toggle{
    width:100%;
    justify-content:space-between;
  }
}

/* API Manager provider logos */
.api-name-cell{
  display:flex;
  align-items:flex-start;
  gap:12px;
}

.api-logo{
  flex:0 0 auto;
  width:38px;
  height:38px;
  display:inline-flex;
  align-items:center;
  justify-content:center;
  border-radius:14px;
  font-size:12px;
  font-weight:900;
  letter-spacing:-.02em;
  color:#fff;
  box-shadow:0 14px 34px rgba(15,23,42,.14);
}

.api-logo-openai{
  background:linear-gradient(135deg,#111827,#374151);
}

.api-logo-serpapi{
  background:linear-gradient(135deg,#2563eb,#06b6d4);
}

.api-logo-google{
  background:linear-gradient(135deg,#4285f4,#34a853);
}

.api-logo-postgres{
  background:linear-gradient(135deg,#336791,#1e3a8a);
}

.api-logo-http{
  background:linear-gradient(135deg,#f97316,#db2777);
}

.api-logo-custom{
  background:linear-gradient(135deg,var(--brand),var(--brand-2));
}

/* Provider logo inside provider column */
.api-provider-cell{
  display:flex;
  align-items:center;
  gap:10px;
}

.api-provider-logo{
  width:24px;
  height:24px;
  object-fit:contain;
  border-radius:7px;
  flex:0 0 auto;
}

/* Project management cards */
.project-grid{
  display:grid;
  grid-template-columns:repeat(auto-fill,minmax(320px,1fr));
  gap:22px;
  margin-top:22px;
}

.project-card{
  padding:22px;
  border-radius:26px;
  background:rgba(255,255,255,.78);
  border:1px solid rgba(255,255,255,.62);
  box-shadow:0 24px 80px rgba(15,23,42,.14);
  backdrop-filter:blur(22px);
}

.project-head{
  display:flex;
  align-items:center;
  gap:16px;
  margin-bottom:18px;
}

.project-logo,
.project-logo-fallback{
  width:64px;
  height:64px;
  border-radius:20px;
  object-fit:contain;
  background:#fff;
  box-shadow:0 16px 38px rgba(15,23,42,.12);
  padding:8px;
}

.project-logo-fallback{
  display:flex;
  align-items:center;
  justify-content:center;
  font-weight:900;
  font-size:24px;
  color:#fff;
  background:linear-gradient(135deg,var(--brand),var(--brand-2));
}

.project-head h2{
  margin:0;
}

.project-head p{
  margin:4px 0 0;
  color:var(--muted);
  font-weight:700;
}

.project-meta{
  display:grid;
  gap:8px;
  margin:16px 0 18px;
  color:var(--muted);
  font-size:13px;
}

.project-actions{
  display:grid;
  grid-template-columns:repeat(4,1fr);
  gap:10px;
}

.project-actions a{
  text-align:center;
  text-decoration:none;
  padding:10px 8px;
  border-radius:14px;
  color:#fff;
  font-size:13px;
  font-weight:800;
  background:linear-gradient(135deg,var(--brand),var(--brand-2));
  box-shadow:0 14px 34px rgba(139,92,246,.18);
}

html[data-theme="light"] .project-card{
  background:rgba(255,255,255,.9);
  border-color:rgba(148,163,184,.28);
}

@media (max-width:860px){
  .project-grid{
    grid-template-columns:1fr;
  }

  .project-actions{
    grid-template-columns:1fr 1fr;
  }
}

/* Keyword Research */
.drive-preview-card{
  padding:0;
  overflow:hidden;
}

.drive-preview{
  width:100%;
  min-height:760px;
  border:0;
  display:block;
  background:#fff;
  border-radius:24px;
}

@media (max-width:860px){
  .drive-preview{
    min-height:620px;
  }
}

.project-actions{
  grid-template-columns:repeat(auto-fit,minmax(110px,1fr));
}

/* Keyword Research dashboard */
.keyword-chart-placeholder{
  min-height:260px;
  display:grid;
  place-items:center;
  border:1px dashed rgba(148,163,184,.5);
  border-radius:22px;
  color:var(--muted);
  background:rgba(255,255,255,.42);
  text-align:center;
  padding:28px;
  font-weight:700;
}

.keyword-sections{
  display:grid;
  gap:18px;
}

.security-note{
  margin-top:18px;
  padding:14px 16px;
  border-radius:16px;
  background:rgba(245,158,11,.12);
  border:1px solid rgba(245,158,11,.28);
  color:var(--muted);
  font-weight:700;
}

.data-control-actions{
  display:grid;
  grid-template-columns:repeat(auto-fit,minmax(280px,1fr));
  gap:18px;
  margin-top:22px;
}

.data-control-box{
  padding:18px;
  border-radius:20px;
  background:rgba(255,255,255,.55);
  border:1px solid rgba(148,163,184,.24);
}

.danger-box{
  border-color:rgba(239,68,68,.28);
  background:rgba(239,68,68,.06);
}

button.danger,
.danger{
  background:linear-gradient(135deg,#ef4444,#be123c) !important;
  color:#fff !important;
}

.security-note{
  margin-top:18px;
  padding:14px 16px;
  border-radius:16px;
  background:rgba(245,158,11,.12);
  border:1px solid rgba(245,158,11,.28);
  color:var(--muted);
  font-weight:700;
}

.chart-grid{
  display:grid;
  grid-template-columns:repeat(2,minmax(0,1fr));
  gap:18px;
  margin-top:18px;
}

.chart-card{
  padding:18px;
  border-radius:22px;
  background:linear-gradient(180deg, rgba(255,255,255,.04), rgba(255,255,255,.02));
  border:1px solid rgba(255,255,255,.08);
  box-shadow:0 10px 30px rgba(0,0,0,.18);
}

.chart-head{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:12px;
  margin-bottom:14px;
}

.chart-head h3{
  margin:0;
  font-size:16px;
  font-weight:800;
}

.chart-head span{
  color:var(--muted);
  font-size:12px;
}

.chart-box{
  min-height:320px;
}

.full-span{
  grid-column:1 / -1;
}

.mini-note{
  margin-top:8px;
  font-size:12px;
  color:var(--muted);
}

@media (max-width: 980px){
  .chart-grid{
    grid-template-columns:1fr;
  }
}
