
@font-face{
  font-family:Vazirmatn;
  src:url('/fonts/vazirmatn-400.woff2') format('woff2');
  font-weight:400;
  font-style:normal;
  font-display:swap;
}
@font-face{
  font-family:Vazirmatn;
  src:url('/fonts/vazirmatn-700.woff2') format('woff2');
  font-weight:700;
  font-style:normal;
  font-display:swap;
}

*{box-sizing:border-box}

:root{
  --bg:#f3f8fa;
  --card:#fff;
  --text:#18334a;
  --muted:#8398a8;
  --line:#e2edf1;
  --soft:#f7fafb;
  --primary:#07988f;
  --primary-dark:#087b77;
  --primary-soft:#eaf9f7;
  --danger:#e45c68;
  --shadow:0 10px 35px rgba(31,72,91,.07);
}

html{direction:rtl}

body{
  margin:0;
  min-height:100vh;
  font-family:Vazirmatn,Tahoma,sans-serif;
  background:
    radial-gradient(circle at 90% 8%,rgba(8,152,143,.06),transparent 27%),
    var(--bg);
  color:var(--text);
  font-size:14px;
}

button,input{
  font:inherit;
}

button{
  cursor:pointer;
}

/* HEADER */

.app-header{
  height:82px;
  padding:0 32px;
  background:#fff;
  border-bottom:1px solid #edf2f4;
  display:flex;
  align-items:center;
  justify-content:space-between;
  box-shadow:0 3px 18px rgba(27,65,83,.025);
}

.brand-block{
  display:flex;
  align-items:center;
  gap:14px;
}

.brand-logo{
  width:48px;
  height:48px;
  border-radius:15px;
  display:grid;
  place-items:center;
  background:linear-gradient(145deg,#11aaa1,#078a83);
  color:#fff;
  font-weight:700;
  font-size:20px;
  box-shadow:0 9px 22px rgba(8,151,143,.20);
}

.brand-block small,
.user-card small{
  color:var(--muted);
  font-size:11px;
}

.brand-block h1{
  margin:2px 0 0;
  font-size:21px;
  line-height:1.5;
}

.user-card{
  display:flex;
  align-items:center;
  gap:11px;
  min-width:205px;
  padding:8px 11px;
  border:1px solid var(--line);
  border-radius:17px;
  background:#fff;
}

.user-avatar{
  width:39px;
  height:39px;
  border-radius:13px;
  background:var(--primary-soft);
  color:var(--primary);
  display:grid;
  place-items:center;
  font-weight:700;
}

.user-card strong{
  display:block;
  margin-top:2px;
  font-size:12px;
}

/* MAIN */

.page{
  width:min(1480px,calc(100% - 48px));
  margin:28px auto 50px;
  display:flex;
  flex-direction:column;
  gap:22px;
}

.card{
  background:var(--card);
  border:1px solid rgba(218,232,237,.9);
  border-radius:24px;
  box-shadow:var(--shadow);
}

/*
  مهم:
  top-grid دیگر دو ستونه نیست.
  master تمام عرض است و total-card پایین‌تر جابه‌جا می‌شود.
*/

.top-grid{
  display:block;
}

.master-card{
  width:100%;
  padding:25px 28px 27px;
}

.card-title{
  display:flex;
  align-items:flex-start;
  gap:13px;
}

.section-number{
  flex:0 0 auto;
  width:36px;
  height:36px;
  border-radius:12px;
  background:var(--primary-soft);
  color:var(--primary);
  display:grid;
  place-items:center;
  font-weight:700;
}

.card-title h2{
  margin:0;
  font-size:18px;
}

.card-title p{
  margin:5px 0 0;
  color:var(--muted);
  font-size:11px;
}

.master-fields{
  margin-top:23px;
  display:grid;
  grid-template-columns:1fr 1fr 2fr;
  gap:18px;
  align-items:end;
}

.field{
  display:block;
}

.field>span{
  display:block;
  margin:0 3px 7px;
  color:#668091;
  font-size:11px;
}

.control{
  position:relative;
}

.control input,
.expense-table input{
  width:100%;
  height:48px;
  padding:0 15px;
  border:1px solid #dbe8ed;
  border-radius:14px;
  outline:none;
  background:#f9fbfc;
  color:var(--text);
  transition:.18s ease;
}

.control input:focus,
.expense-table input:focus{
  border-color:#75cfc9;
  background:#fff;
  box-shadow:0 0 0 4px rgba(8,152,143,.08);
}

.control input::placeholder,
.expense-table input::placeholder{
  color:#a7b5be;
}

.date-control input{
  direction:ltr;
  text-align:right;
  padding-left:42px;
}

.calendar-icon{
  position:absolute;
  left:14px;
  top:50%;
  transform:translateY(-50%);
  color:#6d8998;
  pointer-events:none;
}

/* WORKSPACE */

/*
  ترتیب DOM:
  expenses-card
  reports-card

  total-card داخل top-grid است.
  با CSS grid-area آن را کنار expenses می‌آوریم.
*/

.workspace-grid{
  display:grid;
  grid-template-columns:minmax(0,1fr) 310px;
  gap:22px;
  align-items:start;
}

.expenses-card{
  min-width:0;
  padding:24px;
  grid-column:1;
}

.reports-card{
  grid-column:1 / -1;
  padding:25px 28px;
}

/*
  total-card در DOM بالاتر است، بنابراین با margin و اندازه مناسب
  کارت جمع را به یک کارت جمع‌وجور تبدیل می‌کنیم و نه مستطیل غول‌آسا.
*/

.total-card{
  margin-top:22px;
  width:100%;
  min-height:0;
  height:auto;
  padding:21px 25px;
  border-radius:22px;
  color:#fff;
  display:grid;
  grid-template-columns:48px 1fr auto;
  grid-template-rows:auto auto;
  column-gap:15px;
  align-items:center;
  background:
    radial-gradient(circle at 10% 0%,rgba(255,255,255,.17),transparent 35%),
    linear-gradient(135deg,#0ba89f,#087d78);
  box-shadow:0 13px 30px rgba(7,139,131,.16);
}

.wallet-icon{
  grid-row:1 / 3;
  width:45px;
  height:45px;
  border-radius:14px;
  display:grid;
  place-items:center;
  background:rgba(255,255,255,.14);
}

.total-card>span{
  font-size:12px;
  opacity:.88;
}

.total-card strong{
  grid-column:2;
  font-size:28px;
  line-height:1.3;
}

.total-card small{
  grid-column:3;
  grid-row:1 / 3;
  align-self:center;
  font-size:12px;
  opacity:.85;
}

/* EXPENSE */

.expense-header{
  display:flex;
  justify-content:space-between;
  align-items:center;
  gap:16px;
  margin-bottom:19px;
}

.card-title.compact{
  align-items:center;
}

.add-btn{
  border:1px solid #c9e9e5;
  background:#effaf8;
  color:#087f79;
  height:44px;
  padding:0 17px;
  border-radius:13px;
  font-weight:700;
  display:flex;
  align-items:center;
  gap:7px;
}

.add-btn:hover{
  background:#e3f7f4;
}

.add-btn span{
  font-size:19px;
}

.table-shell{
  width:100%;
  overflow-x:auto;
  border:1px solid #e4edf0;
  border-radius:17px;
  background:#fff;
}

.expense-table{
  width:100%;
  min-width:920px;
  border-collapse:collapse;
  table-layout:fixed;
}

.expense-table th{
  height:45px;
  padding:0 9px;
  background:#f7fafb;
  border-bottom:1px solid #e4edf0;
  color:#8296a4;
  font-size:10px;
  font-weight:700;
}

.expense-table td{
  padding:10px 7px;
  border-bottom:1px solid #edf2f4;
  vertical-align:middle;
  text-align:center;
}

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

.expense-table th:nth-child(1),
.expense-table td:nth-child(1){width:55px}

.expense-table th:nth-child(2),
.expense-table td:nth-child(2){width:145px}

.expense-table th:nth-child(3),
.expense-table td:nth-child(3){width:170px}

.expense-table th:nth-child(4),
.expense-table td:nth-child(4){width:auto}

.expense-table th:nth-child(5),
.expense-table td:nth-child(5){width:105px}

.expense-table th:nth-child(6),
.expense-table td:nth-child(6){width:105px}

.expense-table th:nth-child(7),
.expense-table td:nth-child(7){width:65px}

.expense-table input{
  height:42px;
  border-radius:12px;
  background:#fbfcfd;
}

.purchase-date{
  direction:ltr;
  text-align:center;
}

.amount-input{
  direction:ltr;
  text-align:center;
}

.description-input{
  text-align:right;
}

.row-number{
  color:#526c7c;
  font-weight:700;
}

.file-button{
  min-height:42px;
  width:100%;
  padding:5px 6px;
  border:1px dashed #b9dce0;
  border-radius:11px;
  background:#f1faf9;
  color:#168a87;
  display:flex;
  flex-direction:column;
  align-items:center;
  justify-content:center;
  gap:1px;
  cursor:pointer;
  transition:.18s ease;
}

.file-button:hover{
  border-color:#7bcac5;
  background:#eaf8f6;
}

.file-button input{
  display:none;
}

.file-button span{
  font-size:10px;
  font-weight:700;
}

.file-button small{
  max-width:90px;
  overflow:hidden;
  white-space:nowrap;
  text-overflow:ellipsis;
  color:#8299a5;
  font-size:8px;
}

.delete-row{
  width:34px;
  height:34px;
  padding:0;
  border:0;
  border-radius:10px;
  background:#fff0f1;
  color:var(--danger);
  font-size:19px;
}

.delete-row:hover{
  background:#ffe4e6;
}

/* SAVE */

.bottom-save{
  margin-top:18px;
  padding-top:18px;
  border-top:1px solid #edf2f4;
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:20px;
}

.bottom-total{
  display:flex;
  align-items:baseline;
  gap:8px;
}

.bottom-total>span{
  color:#788e9d;
  font-size:11px;
}

.bottom-total strong{
  color:var(--primary-dark);
  font-size:21px;
}

.bottom-total small{
  color:#8398a5;
  font-size:10px;
}

.save-panel{
  display:flex;
  align-items:center;
  gap:17px;
}

.save-message{
  color:#8498a5;
  font-size:10px;
}

.save-message span{
  color:var(--primary);
  font-weight:700;
}

.save-btn{
  height:45px;
  min-width:160px;
  padding:0 20px;
  border:0;
  border-radius:13px;
  background:linear-gradient(135deg,#0aa59d,#087f7a);
  color:#fff;
  font-weight:700;
  box-shadow:0 8px 18px rgba(8,143,136,.16);
}

/* REPORTS */

.report-dates{
  margin-top:20px;
  display:grid;
  grid-template-columns:1fr 1fr;
  gap:16px;
}

.report-button{
  margin-top:14px;
  height:43px;
  padding:0 20px;
  border:0;
  border-radius:12px;
  background:#edf8f7;
  color:#087f79;
  font-weight:700;
}

#reportsList{
  margin-top:18px;
  display:grid;
  grid-template-columns:repeat(3,minmax(0,1fr));
  gap:12px;
}

.report-card{
  padding:15px;
  border:1px solid #e2ecef;
  border-radius:15px;
  background:#fafcfd;
  line-height:1.9;
}

.report-card b{
  color:var(--text);
}

.report-card small{
  color:var(--muted);
}

#toast{
  position:fixed;
  left:25px;
  bottom:25px;
  z-index:9999;
  max-width:360px;
  padding:12px 18px;
  border-radius:13px;
  background:#173a4b;
  color:#fff;
  box-shadow:0 10px 30px rgba(0,0,0,.14);
  display:none;
}

/* RESPONSIVE */

@media(max-width:1050px){
  .master-fields{
    grid-template-columns:1fr 1fr;
  }

  .description-field{
    grid-column:1 / -1;
  }

  #reportsList{
    grid-template-columns:repeat(2,minmax(0,1fr));
  }
}

@media(max-width:760px){
  .app-header{
    height:auto;
    min-height:76px;
    padding:12px 16px;
  }

  .brand-logo{
    width:42px;
    height:42px;
  }

  .brand-block h1{
    font-size:17px;
  }

  .user-card{
    min-width:0;
    border:0;
    padding:5px;
  }

  .user-card>div:last-child{
    display:none;
  }

  .page{
    width:calc(100% - 24px);
    margin:16px auto 35px;
    gap:14px;
  }

  .card,
  .master-card,
  .expenses-card,
  .reports-card{
    border-radius:19px;
  }

  .master-card,
  .expenses-card,
  .reports-card{
    padding:18px;
  }

  .master-fields,
  .report-dates{
    grid-template-columns:1fr;
  }

  .description-field{
    grid-column:auto;
  }

  .expense-header,
  .bottom-save,
  .save-panel{
    align-items:stretch;
    flex-direction:column;
  }

  .add-btn,
  .save-btn{
    justify-content:center;
    width:100%;
  }

  .total-card{
    grid-template-columns:42px 1fr auto;
    padding:17px;
  }

  .total-card strong{
    font-size:23px;
  }

  #reportsList{
    grid-template-columns:1fr;
  }
}

/* ===== MOBILE CARD LAYOUT FIX ===== */
@media(max-width:760px){

  body{
    overflow-x:hidden !important;
  }

  .page{
    width:calc(100% - 16px) !important;
    margin:10px auto 28px !important;
  }

  .master-card,
  .expenses-card,
  .reports-card{
    width:100% !important;
    padding:14px !important;
  }

  .master-fields{
    display:grid !important;
    grid-template-columns:1fr !important;
    gap:12px !important;
  }

  .top-grid,
  .workspace-grid{
    display:block !important;
  }

  .total-card{
    margin:12px 0 0 !important;
    width:100% !important;
    min-height:105px !important;
    display:grid !important;
    grid-template-columns:44px 1fr auto !important;
    grid-template-rows:auto auto !important;
    align-items:center !important;
    padding:15px !important;
  }

  .expenses-card{
    margin-top:14px !important;
  }

  .expense-header{
    display:flex !important;
    flex-direction:row !important;
    align-items:center !important;
    justify-content:space-between !important;
    gap:8px !important;
  }

  .add-btn{
    width:auto !important;
    height:40px !important;
    padding:0 12px !important;
    white-space:nowrap !important;
    font-size:10px !important;
  }

  .table-shell{
    overflow:visible !important;
    border:0 !important;
    background:transparent !important;
  }

  .expense-table{
    display:block !important;
    width:100% !important;
    min-width:0 !important;
  }

  .expense-table thead{
    display:none !important;
  }

  .expense-table tbody{
    display:grid !important;
    gap:12px !important;
  }

  .expense-table tr{
    position:relative !important;
    display:grid !important;
    grid-template-columns:1fr 1fr !important;
    gap:10px !important;
    width:100% !important;
    padding:14px !important;
    border:1px solid #e2ecef !important;
    border-radius:16px !important;
    background:#fff !important;
    box-shadow:0 6px 20px rgba(34,72,90,.04) !important;
  }

  .expense-table td{
    display:block !important;
    width:auto !important;
    padding:0 !important;
    border:0 !important;
    text-align:right !important;
  }

  .expense-table td:nth-child(1){
    position:absolute !important;
    top:10px !important;
    left:10px !important;
    width:28px !important;
    height:28px !important;
    display:grid !important;
    place-items:center !important;
    border-radius:9px !important;
    background:#eaf9f7 !important;
    color:#07867f !important;
    font-weight:700 !important;
  }

  .expense-table td:nth-child(2){
    grid-column:1 / -1 !important;
    padding-top:34px !important;
  }

  .expense-table td:nth-child(3){
    grid-column:1 / -1 !important;
  }

  .expense-table td:nth-child(4){
    grid-column:1 / -1 !important;
  }

  .expense-table td:nth-child(5){
    grid-column:1 !important;
  }

  .expense-table td:nth-child(6){
    grid-column:2 !important;
  }

  .expense-table td:nth-child(7){
    position:absolute !important;
    top:9px !important;
    right:10px !important;
  }

  .expense-table input{
    width:100% !important;
    min-width:0 !important;
    height:44px !important;
  }

  .file-button{
    width:100% !important;
    min-height:44px !important;
  }

  .bottom-save{
    display:grid !important;
    grid-template-columns:1fr !important;
    gap:10px !important;
    margin-top:14px !important;
  }

  .bottom-total{
    width:100% !important;
    justify-content:center !important;
    padding:12px !important;
    border-radius:14px !important;
    background:#f2faf9 !important;
  }

  .save-panel{
    display:grid !important;
    grid-template-columns:1fr !important;
    gap:10px !important;
  }

  .save-message{
    text-align:center !important;
    line-height:1.9 !important;
  }

  .save-btn{
    width:100% !important;
    min-width:0 !important;
    height:48px !important;
  }

  .reports-card{
    margin-top:14px !important;
  }

  .report-dates{
    display:grid !important;
    grid-template-columns:1fr !important;
    gap:10px !important;
  }

  #reportsList{
    display:grid !important;
    grid-template-columns:1fr !important;
  }
}
